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:
6 months ago
Test name
Executions per second
toFixed(4)
13354571.0 Ops/sec
toPrecision(4).toString()
9280721.0 Ops/sec
(Math.round(*10000)/10000).toString()
787530688.0 Ops/sec
Math.floor fast
777832256.0 Ops/sec
precisition round
748847936.0 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);