assignment vs or

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = [], identity = function(d) { return d; };
   
    var f1 = function(f) {
    a.push(f || identity);
    }
   
    var f2 = function(f) {
    f || (f = identity);
    a.push(f);
    }
};
</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
assignment
f2();
f2(identity);
pending…
or
f1();
f1(identity);
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