Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
Truncation Methods
Testing the various methods for truncating a number to an integer
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36
Browser:
Chrome 151
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one month ago
Benchmark engine:
Benchmark.js
Math.trunc()
4K/s
Bitwise complement
3K/s
Bitwise shift
2K/s
Math.round()
931/s
View exact numbers
Test name
Executions per second
✓
Math.trunc()
4,119 Ops/sec
Bitwise complement
2,632 Ops/sec
Bitwise shift
2,320 Ops/sec
Math.round()
931 Ops/sec
Script Preparation code:
var a = Array.from({length: 10000}, _ => Math.random() * 1000);
Tests:
Bitwise complement
a.map(i => ~~i);
Bitwise shift
a.map(i => i >>> 0);
Math.trunc()
a.map(i => Math.trunc(i));
Math.round()
a.map(i => Math.round(i));