Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Round numbers - OK
(version: 0)
Test between two ways to round up or round down numbers
Comparing performance of:
Using If/Else with ceil/floor vs Using EPSILON
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function customRoundA(number) { if (number - Math.floor(number) >= 0.5) { return Math.ceil(number); } else { return Math.floor(number); } } function customRoundB(number) { return Math.round(number + Number.EPSILON); }
Tests:
Using If/Else with ceil/floor
let roundedNumber = customRoundA(3.7); console.log(roundedNumber); // Output: 4 roundedNumber = customRoundA(2.2); console.log(roundedNumber); // Output: 2
Using EPSILON
let roundedNumber = customRoundB(3.7); console.log(roundedNumber); // Output: 4 roundedNumber = customRoundB(2.2); console.log(roundedNumber); // Output: 2
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Using If/Else with ceil/floor
Using EPSILON
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Comments
Confirm delete:
Do you really want to delete benchmark?