2.0.0 • Published 10 months ago

@shelf/fast-normalize-spaces v2.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

fast-normalize-spaces CircleCInpm.io

fast-normalize-spaces

Install

$ yarn add @shelf/fast-normalize-spaces

Usage

const {normalizeSpaces} = require('@shelf/fast-normalize-spaces');

normalizeSpaces('   hello     \n\n\n   \n \n \t world   ');
// 'hello world'

Benchmark

All tests was launched on MacBook Pro 2020:

  • CPU: 2 GHz Quad-Core Intel Core i5 10th gen
  • RAM: 16 GB 3733 MHz LPDDR4X

Speed

normalize-space-x@shelf/fast-normalize-spacesImprovement
~33 kb: 2 994 ops/s, ±2.34%~33 kb: 3 599 ops/s, ±2.37%16.81%
~330 kb: 267 ops/s, ±1.66%~330 kb: 395 ops/s, ±1.89%32.41%
~3.3 mb: 9 ops/s, ±1.15%~3.3 mb: 31 ops/s, ±3.76%70.97%
~33 mb: 1 ops/s, ±12.91%~33 mb: 3 ops/s, ±2.70%66.67%

You can run yarn benchmark:speed to test on your own.

Memory usage

Text sizenormalize-space-x@shelf/fast-normalize-spacesImprovement
33 kb0.50mb1.29mb-
330 kb6.79mb2.16mb3.14x
3.3 mb77.94mb12.35mb6.3x
33 mb498.12mb112.62mb4.42x
100mb1446.14mb338.11mb4.28x
150mb2003.53mb506.54mb3.96x
200mb2660.09mb674.83mb3.94x

The larger the string the faster it gets. Memory usage is approximately 3x than the input data size.

Set TEXT_SIZE variable value you want in the test.sh script and run the following command to test memory usage:

yarn benchmark:memory

See Also

Publish

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

License

MIT © Shelf