Git Product home page Git Product logo

fast-chunk-string's Introduction

fast-chunk-string CircleCI

Chunk string into equal substrings with unicode support

Credits to stackoverflow.com/a/29202760/2727317

Install

$ yarn add @shelf/fast-chunk-string

Usage

const fastChunkString = require('@shelf/fast-chunk-string');

// the fastest way
fastChunkString('unicorns', {size: 2, unicodeAware: false});
// => ['un', 'ic', 'or', 'ns']

// ignore unicode, still fast but inaccurate
fastChunkString('๐Ÿ˜€๐Ÿ˜ƒ๐Ÿ˜„๐Ÿ˜', {size: 2, unicodeAware: false});
// => ['๐Ÿ˜€', '๐Ÿ˜ƒ', '๐Ÿ˜„', '๐Ÿ˜']

// respect unicode, slow but accurate
fastChunkString('๐Ÿ˜€๐Ÿ˜ƒ๐Ÿ˜„๐Ÿ˜', {size: 2, unicodeAware: true});
// => ['๐Ÿ˜€๐Ÿ˜ƒ', '๐Ÿ˜„๐Ÿ˜']

Benchmarks

Run via yarn benchmark. Measured on Macbook Pro 16" with M1 Max processor.

Running "Without Unicode" suite...
Progress: 100%

  ~33 kb split by 2 kb:
    14 384 027 ops/s, ยฑ0.21%    | 86.51% slower

  ~33 kb split by 1 mb:
    106 655 332 ops/s, ยฑ0.12%   | fastest

  ~330 kb split by 2 kb:
    1 482 220 ops/s, ยฑ0.34%     | 98.61% slower

  ~330 kb split by 1 mb:
    106 442 883 ops/s, ยฑ0.14%   | 0.2% slower

  ~3.3 mb split by 2 kb:
    153 356 ops/s, ยฑ0.19%       | 99.86% slower

  ~3.3 mb split by 1 mb:
    48 824 019 ops/s, ยฑ0.16%    | 54.22% slower

  ~33 mb split by 2 kb:
    14 312 ops/s, ยฑ0.28%        | slowest, 99.99% slower

  ~33 mb split by 1 mb:
    7 059 008 ops/s, ยฑ0.32%     | 93.38% slower

Finished 8 cases!
  Fastest: ~33 kb split by 1 mb
  Slowest: ~33 mb split by 2 kb
Running "Unicode Aware" suite...
Progress: 100%

  ~33 kb split by 2 kb with unicodeAware:
    450 ops/s, ยฑ0.24%   | fastest

  ~33 kb split by 1 mb with unicodeAware:
    428 ops/s, ยฑ0.36%   | 4.89% slower

  ~330 kb split by 2 kb with unicodeAware:
    45 ops/s, ยฑ0.38%    | 90% slower

  ~330 kb split by 1 mb with unicodeAware:
    41 ops/s, ยฑ0.42%    | slowest, 90.89% slower

Finished 4 cases!
  Fastest: ~33 kb split by 2 kb with unicodeAware
  Slowest: ~330 kb split by 1 mb with unicodeAware

See Also

Publish

$ git checkout master
$ yarn version
$ yarn publish
$ git push origin master --tags

License

MIT ยฉ Shelf

fast-chunk-string's People

Contributors

dianakryskuw avatar drewsabuse avatar mpushkin avatar randomhash avatar renovate-bot avatar renovate[bot] avatar richienb avatar terret avatar vladgolubev avatar vladholubiev avatar yuriilevantovych avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fast-chunk-string's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>shelfio/renovate-config)

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

circleci
.circleci/config.yml
  • node 5.1.0
npm
package.json
  • runes 0.4.3
  • string-length 4.0.2
  • @babel/cli 7.20.7
  • @babel/core 7.20.12
  • @shelf/babel-config 1.2.0
  • @shelf/eslint-config 2.27.1
  • @shelf/tsconfig 0.0.9
  • @types/benchmark 2.1.2
  • @types/jest 29.4.0
  • @types/runes 0.4.1
  • benny 3.7.1
  • eslint 8.33.0
  • fast-lorem-ipsum 1.2.0
  • husky 8.0.3
  • jest 29.4.1
  • lint-staged 13.1.0
  • prettier 2.8.3
  • typescript 4.9.4
  • node >=16

  • Check this box to trigger a request for Renovate to run again on this repository

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.