silly conditional

JavaScript performance comparison

Test case created by Mircea Piturca

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var c = [123, 35, 92, 213, 0, 45, 58, 84, 35, 78]
    var fnc = {
        123: function () {},
        35: function () {},
        92: function () {},
        213: function () {},
        0: function () {},
        45: function () {},
        58: function () {console.log('match fnc')},
        84: function () {},
        35: function () {},
        78: function () {}
    }
};
</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
var i = 0,
    il = c.length;

for (; i < il; i += 1) {
  if (c[i] === 58) {
    console.log('match arr')
  }
}
pending…
function
var i = 0,
    il = c.length;

for (; i < il; i += 1) {
    fnc[c[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