Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
floor() vs trunc() vs bitwise hacks (~~, >> 0, etc) vs round()
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Mobile Safari/537.36
Browser:
Chrome Mobile 136
Operating system:
Android
Device Platform:
Mobile
Date tested:
one year ago
<< 0
512K/s
Math.trunc()
511K/s
~~
510K/s
floor
509K/s
>> 0
504K/s
| 0
504K/s
parseInt()
493K/s
round()
468K/s
x - (x % 1)
430K/s
View exact numbers
Test name
Executions per second
✓
<< 0
512,129 Ops/sec
Math.trunc()
511,486 Ops/sec
~~
510,410 Ops/sec
floor
508,629 Ops/sec
>> 0
504,142 Ops/sec
| 0
503,806 Ops/sec
parseInt()
492,752 Ops/sec
round()
467,720 Ops/sec
x - (x % 1)
429,732 Ops/sec
Script Preparation code:
var x = Math.random() * 100000000; var y;
Tests:
floor
y = Math.floor(x);
~~
y = ~~x;
>> 0
y = x >> 0;
| 0
y = x | 0;
<< 0
y = x << 0;
Math.trunc()
y = Math.trunc(x);
x - (x % 1)
y = x - (x % 1);
parseInt()
y = parseInt(x);
round()
y = Math.round(x);