Math.floor, parseInt and left shift (v10)

Revision 10 of this benchmark created on


Description

Measuring performance of removing the fraction off a float using three different methods, Math.floor(), parseInt() and a left shift (<<)

Setup

i = Math.ceil((Math.random() * 10000)).toString();

Teardown


    i = undefined;
  

Test runner

Ready to run.

Testing in
TestOps/sec
+
var j = +i
ready
bitwise or
var j = i | 0
ready
bitwise not
var j = ~~i;
ready
left shift
var j = i << 0;
ready
parseInt()
var j = parseInt(i);
ready
Math.floor()
var j = Math.floor(i);
ready

Revisions

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