Converting float to integer (Math.floor)

Benchmark created on


Setup

const numbers = Array.from({ length: 1000000 }, () => Math.random() * 1000);

Test runner

Ready to run.

Testing in
TestOps/sec
Math.floor
for (const num of numbers) {
  let result = Math.floor(num);
}
ready
Math.trunc
for (const num of numbers) {
  let result = Math.trunc(num);
}
ready
Bitwise OR
for (const num of numbers) {
  let result = num | 0;
}
ready
Bitwise RIGHT
for (const num of numbers) {
  let result = num >> 0;
}
ready
Bitwise LEFT
for (const num of numbers) {
  let result = num << 0;
}
ready
Bitwise NOT
for (const num of numbers) {
  let result = ~~num;
}
ready
parseInt
for (const num of numbers) {
  let result = parseInt(num);
}
ready

Revisions

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