toFixed vs parseInt vs ~~ vs | 0 vs Math.floor2 (v4)

Revision 4 of this benchmark created on


Setup

var a = 232.22;
    
    function toInt(num) {
      return num | 0;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
toFixed
a.toFixed()
ready
parseInt
parseInt(a, 10)
ready
~~
~~
a
ready
Math.floor
Math.floor(a)
ready
| 0
a | 0
ready
custom to int use |0
toInt(a)
ready

Revisions

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