Created
October 8, 2015 23:14
-
-
Save srl295/72a8a2d88c8f45218d63 to your computer and use it in GitHub Desktop.
Number format perf test for Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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