String to int

JavaScript performance comparison

Revision 3 of this test case created by Spencer Creasey

Info

Not all values return 200.

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Multiply by 1
var x = 1 * '0200',  // 200
    y = 1 * '200px', // NaN
    z = 1 * '2e2';   // 200
pending…
Number()
var x = Number('0200'),  // 200
    y = Number('200px'), // NaN
    z = Number('2e2');   // 200
pending…
Unary +
var x = +'0200',  // 200
    y = +'200px', // NaN
    z = +'2e2';   // 200
pending…
Bitwise double negation ~~
var x = ~~'0200',  // 200
    y = ~~'200px', // 0
    z = ~~'2e2';   // 200
pending…
parseInt()
var x = parseInt('0200', 10),  // 200
    y = parseInt('200px', 10), // 200
    z = parseInt('2e2', 10);   // 2 (parseInt('2e2') == 200)
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