if versus functionandif

JavaScript performance comparison

Test case created

Preparation code

<script>
  var a = ['w', '1', 'o', '1', 'r', '1', 'l', '1', 'd', '1'];
</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
if first
var write = function(c) {
  console.log(c)
}

var hello = function(arr) {
  for (var i = 0, n = arr.length; i < n; i++) {
    if (isNaN(arr[i])) {
      write(arr[i]);
    }
  }
}

hello(a);
pending…
function first
var write = function(c) {
  if (isNaN(a)) {
    console.log(a)
  }
}

var hello = function(arr) {
  for (var i = 0, n = arr.length; i < n; i++) {
    write(arr[i]);
  }
}

hello(a);
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