Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Bitwise Truncation Methods
(version: 1)
Comparing performance of:
~~num vs num | 0 vs num << 0 vs num >> 0 vs num >>> 0
Created:
one month ago
by:
Guest
Jump to the latest result
Script Preparation code:
"use strict"; const arr = Array.from({length: 1000}, (function(){return Math.random()*1000}));
Tests:
~~num
"use strict"; let x = 0; for (let i=0; i<1000; i++) { x = ~~(arr[i]); }
num | 0
"use strict"; let x = 0; for (let i=0; i<1000; i++) { x = (arr[i]) | 0; }
num << 0
"use strict"; let x = 0; for (let i=0; i<1000; i++) { x = (arr[i]) << 0; }
num >> 0
"use strict"; let x = 0; for (let i=0; i<1000; i++) { x = (arr[i]) >> 0; }
num >>> 0
"use strict"; let x = 0; for (let i=0; i<1000; i++) { x = (arr[i]) >>> 0; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
~~num
num | 0
num << 0
num >> 0
num >>> 0
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.5 Safari/605.1.15
Browser/OS:
Safari 26 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
~~num
2791918.0 Ops/sec
num | 0
2795665.2 Ops/sec
num << 0
2795462.8 Ops/sec
num >> 0
2792090.8 Ops/sec
num >>> 0
2793578.0 Ops/sec
Related benchmarks:
Test for
Test for
testgvstrgvstgv
Loop comparison
while, for, for-of, map
for loop speed comparison
Truncation Methods 2
Truncation Methods 3
Truncation Methods 5
Comments
Confirm delete:
Do you really want to delete benchmark?