performance of parseInt() (v22)

Revision 22 of this benchmark created by Wonderfool on


Description

Seeing what happens when it's fed a number (as is often the case in Box2D)

Setup

var someFloat = Math.random() * 10;
    var someInt = Math.round(Math.random() * 10);

Test runner

Ready to run.

Testing in
TestOps/sec
parseInt(x)
var result;

result = parseInt(someFloat);
result = parseInt(someInt);
ready
parseInt(x, 10)
var result;

result = parseInt(someFloat, 10);
result = parseInt(someInt, 10);
ready
~~x
var result;

result = ~~someFloat;
result = ~~someInt;
ready
Math.floor(x)
var result;

result = Math.floor(someFloat);
result = Math.floor(someInt);
ready
Math.ceil(x)
var result;

result = Math.ceil(someFloat);
result = Math.ceil(someInt);
ready
Math.round()
var result;

result = Math.round(someFloat);
result = Math.round(someInt);
ready
x | 0
var result;

result = someFloat | 0;
result = someInt | 0;
ready

Revisions

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