Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
* 10, round vs trunc vs floor vs parseFloat vs ~~ vs 0 | vs parseInt vs parseInt, 10 loop
fastest from float to int with multiplication
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0
Browser:
Firefox 123
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
trunc
3857105.2 Ops/sec
round
3845987.2 Ops/sec
floor
3858572.5 Ops/sec
parseFloat to int
11734.7 Ops/sec
~~
3888677.5 Ops/sec
|0
3912829.8 Ops/sec
parseInt
3732859.0 Ops/sec
parseInt, 10
3873018.2 Ops/sec
Script Preparation code:
var count = 1000;
Tests:
trunc
for (var i = 0; i < count; i++) { Math.trunc(12.34 * 10); Math.trunc(567.89 * 10); }
round
for (var i = 0; i < count; i++) { Math.round(12.34 * 10); Math.round(567.89 * 10); }
floor
for (var i = 0; i < count; i++) { Math.floor(12.34 * 10); Math.floor(567.89 * 10); }
parseFloat to int
for (var i = 0; i < count; i++) { parseFloat((12.34 * 10).toFixed()); parseFloat((567.89 * 10).toFixed()); }
~~
for (var i = 0; i < count; i++) { ~~(12.34 * 10); ~~(567.89 * 10); }
|0
for (var i = 0; i < count; i++) { (12.34 * 10 |0); (567.89 * 10 |0); }
parseInt
for (var i = 0; i < count; i++) { parseInt(12.34 * 10); parseInt(567.89 * 10); }
parseInt, 10
for (var i = 0; i < count; i++) { parseInt(12.34 * 10, 10); parseInt(567.89 * 10, 10); }