Array Pushing: Object Function Wrapper Versus Object

JavaScript performance comparison

Test case created by Vaughn

Info

Comparison at how fast wrapping an object in a function (for code reduction) is when pushing new arrays into it versus just using a plain object.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var tests = [];
   
    function test(a, b, c, i) {
      i = i || {};
      i.a = a;
      i.b = b;
      i.c = c;
      return i;
    }
   
    var tests2 = [];
};
</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
Object Function Wrapper
tests.push(test("abc", 1, true));
pending…
Object
tests2.push({
  a: "abc",
  b: 1,
  c: true
});
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