decimalplaces

JavaScript performance comparison

Test case created by zaphod1984

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var num = Math.random();
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
toFixed, 2 decimal places
var result = parseFloat(num.toFixed(2));
pending…
round, 2 decimal places
var result = Math.round(num * 100) / 100;
pending…
toFixed, 3 decimal places
var result = parseFloat(num.toFixed(3));
pending…
round, 3 decimal places
var result = Math.round(num * 1000) / 1000;
pending…
toFixed, 5 decimal places
var result = parseFloat(num.toFixed(5));
pending…
round, 5 decimal places
var result = Math.round(num * 100000) / 100000;
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment