New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

fastpad

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastpad

Fastest pad left implementation, 2 millions ops in 48ms.

latest
Source
npmnpm
Version
2.0.4
Version published
Weekly downloads
9
50%
Maintainers
1
Weekly downloads
 
Created
Source

FastPad

FastPad is a blazing fast left-pad function with performances better than pad-left and the new native function repeat (Present in the new ES6 and Node 6).

How is it possible to be faster than pad-left, the one used by google and so on?

The algorithm is the Egyptian string concatenation algorithm found in the British museum by researchers a while ago.

Even though pad-left is very fast, I've done it better by caching the result as well as there is no need to redo the math if the input is the same as the cached input.

How to use

$ npm install fastpad --save 

var pad = require('fastpad');

console.log(pad('0',4,'4'));

On a small scale, the execution time for a single record is 5 microseconds compared to 6 microseconds which the famous pad-left has.

Below you can see some benchmark results ( each test was ran 100 times ):

PAD That returns 0004

pad('0',4,4) Result: 2.000.000 ops /  48 miliseconds
pad('0',4,'4') Result: 20.000.000 ops / 439 miliseconds
pad('0',4,4) Result: 200.000.000 ops / 3.9 seconds

PAD That returns 000000test

pad('0',10,'test') Result: 200.000.000 ops / 4.2 seconds

Author - Alexandru-Mihai Spinu

Keywords

fastpad

FAQs

Package last updated on 05 May 2016

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