best of string to number conversion (v41)

Revision 41 of this benchmark created on


Setup

var abc = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];

Test runner

Ready to run.

Testing in
TestOps/sec
Number()
var result = 0,
    converted;
for (var i = 0, len = abc.length; i < len; ++i) {
  converted = Number(abc[i]);
  if (!isNaN(converted)) {
    result += converted
  }
}
ready
parsetInt()
var result = 0,
    converted;
for (var i = 0, len = abc.length; i < len; ++i) {
  converted = parseInt(abc[i], 10);
  if (!isNaN(converted)) {
    result += converted
  }
}
ready
parseFloat()
var result = 0,
    converted;
for (var i = 0, len = abc.length; i < len; ++i) {
  converted = parseFloat(abc[i]);
  if (!isNaN(converted)) {
    result += converted
  }
}
ready
implicit
var result = 0,
    converted;
for (var i = 0, len = abc.length; i < len; ++i) {
  converted = +abc[i];
  if (!isNaN(converted)) {
    result += converted
  }
}
ready
~~
var result = 0,
    converted;
for (var i = 0, len = abc.length; i < len; ++i) {
  converted = ~~abc[i];
  if (!isNaN(converted)) {
    result += converted
  }
}
ready

Revisions

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