Number flooring (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script>
  var foo = 5.98897982734987897234234;
  var bar = 2.9834988349834;
  var qux = 9.34872734;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
parseInt
var result;
for (var i = 0, j = 100000; i < j; i += 1) {
 result = parseInt(foo, 10);
 result = parseInt(bar, 10);
 result = parseInt(qux, 10);
}
ready
~~
var result;
for (var i = 0, j = 100000; i < j; i += 1) {
 result = ~~ (foo);
 result = ~~ (bar);
 result = ~~ (qux);
}
ready
Math.floor
var result;
for (var i = 0, j = 100000; i < j; i += 1) {
 result = Math.round(foo, 2);
 result = Math.round(bar, 2);
 result = Math.round(qux, 2);
}
ready
toFixed
var result;
for (var i = 0, j = 100000; i < j; i += 1) {
 result = foo.toFixed(2);
 result = bar.toFixed(2);
 result = qux.toFixed(2);
}
ready
var result;
for (var i = 0, j = 100000; i < j; i += 1) {
 result = Math.floor(foo);
 result = Math.floor(bar);
 result = Math.floor(qux);
}
ready

Revisions

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