performance of parseInt()

JavaScript performance comparison

Revision 23 of this test case created

Info

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

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var someFloat = 999.99;
    var someInt = 999;
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
parseInt(x)
var result;

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

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

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

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

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

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

result = someFloat | 0;
result = someInt | 0;
pending…
parseFloat(x)
var result;

result = parseFloat(someFloat);
result = parseFloat(someInt);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment