Skip to content

Instantly share code, notes, and snippets.

@srl295
Created October 8, 2015 23:14
Show Gist options
  • Save srl295/72a8a2d88c8f45218d63 to your computer and use it in GitHub Desktop.
Save srl295/72a8a2d88c8f45218d63 to your computer and use it in GitHub Desktop.
Number format perf test for Node.js
var process = require('process');
function delta(d) {
return d[0] + (d[1]/1e9);
}
var n = 0.1; // specific # affects speed
var nn = [];
var nf;
if(process.versions.icu) { // this was added in https://github.com/nodejs/node/issues/3089
// options affect speed
nf = new Intl.NumberFormat([], {minDecimalPlaces: 2});
} else {
nf = {
format: function(nnn) { return nnn.toLocaleString(); }
};
}
var p0 = process.hrtime();
for(var k=0;k<10000;k++) { /*n.toString();*/ nf.format(n); }
var p1 = process.hrtime(p0);
console.log((process.versions.icu||'none') + " : " + delta(p1) + " : " + nf.format(n));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment