toLocaleString or manually

JavaScript performance comparison

Test case created by peterbe

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
numberWithCommas
function numberWithCommas(x) {
  var parts = x.toString().split('.');
  parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  return parts.join('.');
}
for (var i=0; i < 100000; i++) {
  numberWithCommas(i)
}
pending…
toLocaleString
function numberWithCommas(x) {
  return x.toLocaleString()
}
for (var i=0; i < 100000; i++) {
  numberWithCommas(i)
}
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 Comments