performance of parseInt()

JavaScript performance comparison

Revision 35 of this test case created by Tri

Info

Side note on big numbers (32-bit or bigger)

The result of binary operations are signed 32-bit numbers. Standard ECMA-262 5.1

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var str="4";
};
</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 i=parseInt(str)
pending…
parseInt(x, 10)
var i=parseInt(str, 10)
pending…
+x
var i=+str
pending…
~~x
var i=~~str
pending…
parseFloat(x)
var i=parseFloat(str)
pending…
Number(x)
var i=Number('4')
pending…
Math.ceil(x)
var i=Math.ceil(str)
pending…
Math.round()
var i=Math.round(str)
pending…
x >> 0
var i=str >> 0
pending…
x >>> 0
var i=str >>> 0
pending…
| 0
var i=str|0
pending…
x * 1
var i=str * 1
pending…
Math.floor
var i=Math.floor(str)
pending…
-0
var i=str-0
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