int parse with check

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = ['q','1',2,'q','3',4,'q','5',6,'q','7',8,'q','9',10];
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Clear parse int
var b = [];
for (var i = 0; i < a.length; i++){
  var tmp = a[i];
  b[i] = parseInt(tmp);
}
pending…
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)}
}
pending…
Another clear parse int
var b = [];
for (var i = 0; i < a.length; i++){
  b[i] = parseInt(a[i]);
}
pending…

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

Compare results of other browsers

0 comments

Add a comment