Function call - cache arguments or direct pass

JavaScript performance comparison

Test case created by Michael Poland

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function returningFunction() {
      var retArr = [Math.random(), Math.random(), Math.random()];
      return retArr;
    }
   
    function processingFunction(x,y,z) {
      var retVal = x*y*z*x*y*z;
      return retVal;
    }
};
</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
Cache returning value
var arr = returningFunction();
var x = arr[0];
var y = arr[1];
var z = arr[2];
processingFunction(x,y,z);
pending…
Direct pass
var arr = returningFunction();
processingFunction(arr[0],arr[1],arr[2]);
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