Math.floor, parseInt, left shift and binary OR (v4)

Revision 4 of this benchmark created by Dj Gilcrease on


Description

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

Setup

i = Math.random() * 10000;

Teardown


    delete i;
  

Test runner

Ready to run.

Testing in
TestOps/sec
Math.floor()
Math.floor(i);
ready
parseInt()
parseInt(i);
ready
left shift
i << 0;
ready
binary OR
0|i
ready
Tilde
~~i
ready
function call overhead
(function(x){return 0|x;}(i))
ready

Revisions

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