GithubHelp home page GithubHelp logo

watson / quickly-count-substrings Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 1.0 4 KB

Fast module for counting the number of occurrences of a substring inside a string

License: MIT License

JavaScript 91.38% Shell 8.62%

quickly-count-substrings's Introduction

quickly-count-substrings

Fast module for counting the number of occurrences of a substring inside a string.

Build status js-standard-style

Installation

npm install quickly-count-substrings --save

Usage

const count = require('quickly-count-substrings')

const str = 'The quick brown fox jumps over the lazy dog'

count(str, 'o') // => 4

API

result = count(str, substr[, options])

Returns number of occurrences of substr in str.

Arguments:

  • str - The string to search in
  • substr - The string to search for
  • options - Optional. If {overlap: true}, overlapping substrings will be counted (default: {overlap: false})

Benchmark

Counting substrings in a 24MB string:

# quickly-count-substrings
ok ~44 ms (0 s + 43676071 ns)

# count-substring
ok ~134 ms (0 s + 133563148 ns)

# string-occurrence
ok ~184 ms (0 s + 183978927 ns)

# needle-string
ok ~116 ms (0 s + 115521420 ns)

# regex-occurrence
ok ~169 ms (0 s + 169180879 ns)

# count-strings
ok ~491 ms (0 s + 490783663 ns)

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.