fast-format
This is a string formatter like util.format()
method in Node.js, supports just only %s
placeholder but accordingly faster than that. It will be one of the best solution if need a speed rather than complex formatting.
Usage
Same as util.format()
method.
If use one formatting repeatedly, recommended to compile the formatString
in advance.
format
Example
let s = ;console; // => 'Hello, world!'
let f = format;let s1 = ;console; // => 'Hello, world!'let s2 = ;console; // => 'Howdy, World!'
Benchmark
// Bench 1let s = Date;for let i = 0 len = 100000000; i < len; i++ ;console;
// Bench 2let s = Date;let f = format;for let i = 0 len = 100000000; i < len; i++ ;console;
environment1: Core i7 2.2GHz + Node.js v6.9.5
module | time | bench |
---|---|---|
fast-format | 12,388 msec | 2 |
fast-format | 22,039 msec | 1 |
util.format | 28,659 msec | 1 |
environment2: Core i7 2.2GHz + Google Chrome 56.0.2924.87
module | time | bench |
---|---|---|
fast-format | 12,898 msec | 2 |
fast-format | 22,705 msec | 1 |
util.format | 99,103 msec | 1 |
The util.format()
method was converted with Browserify
to run on the browser.
Installation
via npm
npm install fast-format --save
via Bower
bower install fast-format
directly (in case of the browser)
Browser Support
Google Chrome, Firefox, Safari, Opera, Microsoft Edge and IE 6+
License
MIT