int parse with check

Benchmark created on


Setup

var a = ['q','1',2,'q','3',4,'q','5',6,'q','7',8,'q','9',10];

Test runner

Ready to run.

Testing in
TestOps/sec
Clear parse int
var b = [];
for (var i = 0; i < a.length; i++){
  var tmp = a[i];
  b[i] = parseInt(tmp);
}
ready
Parse int with check
var b = [];
for (var i = 0; i < a.length; i++){
  var tmp = a[i];
  if (typeof tmp === 'number') { b[i] = tmp }
  else if (typeof tmp === 'string') {b[i] = parseInt(tmp)}
}
ready
Another clear parse int
var b = [];
for (var i = 0; i < a.length; i++){
  b[i] = parseInt(a[i]);
}
ready

Revisions

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