Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Truncate decimal
(version: 1)
Becnhmark to test different floating points truncating methods
Comparing performance of:
Floor vs Bitwise vs Bitwise NOT vs Parse
Created:
9 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const numbers = (new Array(5000)).map(() => Math.random() * 10000);
Tests:
Floor
let truncated; while(true){ const number = numbers.pop() if(number === undefined) break; truncated = Math.floor(number); }
Bitwise
let truncated; while(true){ const number = numbers.pop() if(number === undefined) break; truncated = number | 0; }
Bitwise NOT
let truncated; while(true){ const number = numbers.pop() if(number === undefined) break; truncated = ~~number; }
Parse
let truncated; while(true){ const number = numbers.pop() if(number === undefined) break; truncated = parseInt(number); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Floor
Bitwise
Bitwise NOT
Parse
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Floor
54852436.0 Ops/sec
Bitwise
60659580.0 Ops/sec
Bitwise NOT
59274400.0 Ops/sec
Parse
61489312.0 Ops/sec
Related benchmarks:
Round Numbers to 2 digits
Round Numbers to 2 digits
String looping test
get precision from number string
* 10, round vs trunc vs floor vs parseFloat vs ~~ vs 0 | vs parseInt vs parseInt, 10
* 10, round vs trunc vs floor vs parseFloat vs ~~ vs 0 | vs parseInt vs parseInt, 10 loop
test ipsum
Float to Integer
Various Ways to cast float to Integer
Comments
Confirm delete:
Do you really want to delete benchmark?