Number flooring (v9)

Revision 9 of this benchmark created on


Preparation HTML

<script>
  var foo = 5.98897982734987897234234;
  var bar = 2.9834988349834;
  var qux = 9.34872734;
  var result1, result2, result3;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
parseInt
for (var i = 0, j = 100000; i < j; ++i) {
  result1 = parseInt(foo, 10);
  result2 = parseInt(bar, 10);
  result3 = parseInt(qux, 10);
}
ready
~~
for (var i = 0, j = 100000; i < j; ++i) {
  result1 = ~~(foo);
  result2 = ~~(bar);
  result3 = ~~(qux);
}
ready
Math.floor
for (var i = 0, j = 100000; i < j; ++i) {
  result1 = Math.floor(foo);
  result2 = Math.floor(bar);
  result3 = Math.floor(qux);
}
ready
toFixed (equiv to round)
for (var i = 0, j = 100000; i < j; ++i) {
  result1 = foo.toFixed();
  result2 = bar.toFixed();
  result3 = qux.toFixed();
}
ready
>>
for (var i = 0, j = 100000; i < j; ++i) {
  result1 = foo >> 0;
  result2 = bar >> 0;
  result3 = qux >> 0;
}
ready
Math.round
for (var i = 0, j = 100000; i < j; ++i) {
  result1 = Math.round(foo);
  result2 = Math.round(bar);
  result3 = Math.round(qux);
}
ready
<<
for (var i = 0, j = 100000; i < j; ++i) {
  result1 = foo << 0;
  result2 = bar << 0;
  result3 = qux << 0;
}
ready
Math.ceil
for (var i = 0, j = 100000; i < j; ++i) {
  result1 = Math.ceil(foo);
  result2 = Math.ceil(bar);
  result3 = Math.ceil(qux);
}
ready

Revisions

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