javascript trunc (v3)

Revision 3 of this benchmark created on


Preparation HTML

<script>
  var n = 100.4;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
1
Math.round(n > 0 ? n - 0.5 : n + 0.5 );
ready
2
Math[n > 0 ? "floor" : "ceil"](n);
ready
3
n | 0; // bitwise operators convert operands to 32-bit integers
ready
4
isNaN(n) ? NaN : n | 0;
ready

Revisions

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