Number() vs parseInt() vs plus vs bitwise (v19)

Revision 19 of this benchmark created on


Setup

t = ["10", "0", "-123", "128371873", "-9199191", "00"];
  v = 123;

Test runner

Ready to run.

Testing in
TestOps/sec
Number Constructor
v = 0;
for (var i = 0; i < 6; i++) {
v += Number(t[i]);
}
ready
parseInt
v = 0;
for (var i = 0; i < 6; i++) {
v += parseInt(t[i]);
}
ready
Plus operator
v = 0;
for (var i = 0; i < 6; i++) {
v += +t[i];
}
ready
Bitwise >> (right shift)
v = 0;
for (var i = 0; i < 6; i++) {
v += t[i] >> 0;
}
ready
Multiply (force cast)
v = 0;
for (var i = 0; i < 6; i++) {
v += t[i] * 1;
}
ready
not not
v = 0;
for (var i = 0; i < 6; i++) {
v += ~~t[i];
}
ready
"10"<<0
v = 0;
for (var i = 0; i < 6; i++) {
v += t[i]<<0;
}
ready
"10">>>0
v = 0;
for (var i = 0; i < 6; i++) {
v += t[i]>>>0;
}
ready
parseInt("10", 10)
v = 0;
for (var i = 0; i < 6; i++) {
v += parseInt(t[i], 10);
}
ready
Bitwise or
v = 0;
for (var i = 0; i < 6; i++) {
v += t[i] | 0;
}
ready

Revisions

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