Measure performance of bitwise OR vs. Math.round in JavaScript.
JavaScript
const num = 5.9;
const repetitions = 1000000000;
console.time('Bitwise OR');
for (let i = 0; i < repetitions; i++) {
const truncated = num | 0;
}
console.timeEnd('Bitwise OR');
console.time('Math.round');
for (let i = 0; i < repetitions; i++) {
const rounded = Math.round(num);
}
console.timeEnd('Math.round');