Passing by object reference

JavaScript performance comparison

Test case created by Oliver Caldwell

Info

I want to see if passing a set of large strings directly to a function makes copies in memory. It would therefore be slower than passing an object reference containing the same strings.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var stringData = {
        foo: new Array(100000).join('abcABC123'),
        bar: new Array(100000).join('ABCabc987')
    };
   
    function target(){}
};
</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
Passing as seperate arguments
target(stringData.foo, stringData.bar);
pending…
Passing as an object reference
target(stringData);
pending…
Passing as two objects (to rule our argument count being a factor)
target(stringData, stringData);
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