Math.round vs bitshift perfomance

Benchmark created on


Description

This tests the peformance of Math.round() vs bitshifting vs a bitshift function to see what the fastest way to round numbers is

Setup

const round =  x => x + 0.5 << 0 

Test runner

Ready to run.

Testing in
TestOps/sec
Math.Round
for (let i = 0; i < 50; i++){
	Math.round(50/i)
}
ready
Bitshift
for (let i = 0; i < 50; i++){
	(50 / i) + 0.5 << 0
}
ready
Bitshift function

for (let i = 0; i < 50; i++){
	round(50/i)
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.