Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@shelf/fast-normalize-spaces

Package Overview
Dependencies
Maintainers
63
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shelf/fast-normalize-spaces

A faster (by 16-70%) implementation of "normalize-space-x" package that uses at least 3x less RAM

  • 2.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
63
Created
Source

fast-normalize-spaces CircleCI

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

FAQs

Package last updated on 02 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc