@shelf/fast-chunk-string
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

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

/@shelf/fast-chunk-string/

    Package Sidebar

    Install

    npm i @shelf/fast-chunk-string

    Weekly Downloads

    719

    Version

    3.0.0

    License

    MIT

    Unpacked Size

    7.63 kB

    Total Files

    11

    Last publish

    Collaborators

    • vladmarchuk
    • vadymaslovskyi
    • andrew_batutin
    • marianna-milovanova
    • petro.bodnarchuk
    • kateryna-kochina
    • maksym.tarnavskyi
    • andrii-nastenko
    • mykhailo.yatsko
    • ahavrysh
    • nikita_shelf
    • maciej.orlowski
    • monopotan
    • andrew214
    • bogdan.kolesnyk
    • andrii.batutin
    • kristina.zhak
    • anton-russo
    • mmazurowski
    • mateuszgajdashelf
    • kchlon
    • dmytro.harazdovskiy
    • duch0416
    • i5adovyi
    • olesiamuller
    • mykola.khytra
    • yuliiakovalchuk
    • el_scrambone
    • bodyaflesh
    • andriisermiahin
    • mpushkin
    • batovpavlo
    • domovoj
    • vozemer
    • oleksii.dymnich
    • dima-bond
    • maksym.hayovets
    • oles.zadorozhnyy
    • ss1l
    • gemshelf
    • hartzler
    • vladgolubev
    • hmelenok
    • knupman
    • maaraanas
    • terret
    • chapelskyi.slavik
    • pihorb
    • irynah
    • diana.kryskuv
    • andy.raven
    • rafler
    • sskalp88
    • demiansua
    • yuriil
    • ktv18
    • drews_abuse
    • rostyslav-horytskyi
    • whodeen