Conversion to Integer (v2)

Revision 2 of this benchmark created by Andrew J. Baker on


Description

Using ~~ and | 0, etc. it isn't particularly apparent what the developer's intentions are.

Preparation HTML

<script>
  var n = Math.random() * 1000;
  var CONVERT_TO_INTEGER = 0;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
bitwise NOT
~~n;
ready
bitwise OR
n | 0;
ready
Math.floor
Math.floor(n);
ready
Math.ceil
Math.ceil(n);
ready
Math.round
Math.round(n);
ready
parseInt
parseInt(n, 10);
ready
Bitwise OR w/ variable for readability
n | CONVERT_TO_INTEGER;
ready

Revisions

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

  • Revision 1: published by alpicola on
  • Revision 2: published by Andrew J. Baker on