parseInt() vs everything (v2)

Revision 2 of this benchmark created on


Description

Casting string to integer, for example after reading from localStorage.

Setup

var strings = [];
    var numbers = [];
    for (var i = 0; i < 10000; ++i) {
    strings.push("" + i);
    numbers.push(0);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
parseInt
var i = strings.length;
while (--i >= 0) {
numbers[i]=parseInt(strings[i], 10);
}
ready
+
var i = strings.length;
while (--i >= 0) {
numbers[i]=+strings[i];
}
ready
~~
var i = strings.length;
while (--i >= 0) {
numbers[i]=~~strings[i];
}
ready
| 0
var i = strings.length;
while (--i >= 0) {
numbers[i]=strings[i] | 0;
}
ready
>> 0
var i = strings.length;
while (--i >= 0) {
numbers[i]=strings[i] >> 0;
}
ready
>>> 0
var i = strings.length;
while (--i >= 0) {
numbers[i]=strings[i] >>> 0;
}
ready
Number()
var i = strings.length;
while (--i >= 0) {
numbers[i]=Number(strings[i]);
}
ready
* 1
var i = strings.length;
while (--i >= 0) {
numbers[i]=strings[i] * 1;
}
ready
Math.floor()
var i = strings.length;
while (--i >= 0) {
numbers[i]=Math.floor(strings[i]);
}
ready
- 0
var i = strings.length;
while (--i >= 0) {
numbers[i]=strings[i] - 0;
}
ready
~
var i = strings.length;
while (--i >= 0) {
numbers[i]=~strings[i];
}
ready

Revisions

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