Math.floor vs Math.round vs parseInt vs Bitwise (v101)

Revision 101 of this benchmark created by gfx on


Description

String-to-Int in all form possible

Preparation HTML

<script>
var num = String(Math.random() * 255);
function x(e) { return Math.floor(e)|0; }
</script>

Teardown


    num = String(Math.random() * 255);
  

Test runner

Ready to run.

Testing in
TestOps/sec
Math.floor
Math.floor(num);
ready
Math.round
Math.round(num);
ready
parseInt
parseInt(num,10);
ready
Bitwise |
num | 0;
ready
Bitwise
num >> 1;
ready
typed function
x(num);
ready

Revisions

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