Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
toFixed vs toPrecision vs Math.round() vs Math.floorfast vs MDN round_to_precision
Added MDN round to precision function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:144.0) Gecko/20100101 Firefox/144.0
Browser:
Firefox 144
Operating system:
Linux
Device Platform:
Desktop
Date tested:
7 months ago
(Math.round(*10000)/10000).toString()
787.5M/s
Math.floor fast
777.8M/s
precisition round
748.8M/s
toFixed(4)
13.4M/s
toPrecision(4).toString()
9.3M/s
View exact numbers
Test name
Executions per second
✓
(Math.round(*10000)/10000).toString()
787,530,688 Ops/sec
Math.floor fast
777,832,256 Ops/sec
precisition round
748,847,936 Ops/sec
toFixed(4)
13,354,571 Ops/sec
toPrecision(4).toString()
9,280,721 Ops/sec
Script Preparation code:
var someFloat = 0.123456789; var round_to_precision = function (x, precision) { var y = +x + (precision === undefined ? 0.5 : precision/2); return y - (y % (precision === undefined ? 1 : +precision)); };
Tests:
toFixed(4)
someFloat.toFixed(4);
toPrecision(4).toString()
someFloat.toPrecision(4);
(Math.round(*10000)/10000).toString()
(Math.round(someFloat*10000)/10000);
Math.floor fast
~~(someFloat * 10000) / 10000;
precisition round
round_to_precision(someFloat, 4);