optional parameters

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var param1 = (Math.random() < 0.2) ? undefined : 2;
    var param2 = (Math.random() < 0.5) ? undefined : 3;
    var param3 = (Math.random() < 0.8) ? undefined : 4;
};
</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
optional parameters1
param1 || (param1 = 10);
param2 || (param2 = 11);
param3 || (param3 = 12);
pending…
optional parameters2
param1 = param1 || 10;
param2 = param2 || 11;
param3 = param3 || 12;
pending…
optional parameters3
if (!param1) param1 = 10;
if (!param2) param2 = 11;
if (!param3) param3 = 12;
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment