5cp

JavaScript performance comparison

Test case created by Stoyan

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function copyFive(obj, a, b, c, d, e, f) {
      obj = obj || {};
   
      if (window.__DEV__) {
        if (f) {
          throw new Error('Too many');
        }
      }
   
      var args = [a, b, c, d, e];
      var ii = 0,
          v;
      while (args[ii]) {
        v = args[ii++];
        for (var k in v) {
          obj[k] = v[k];
        }
   
   
        if (v.hasOwnProperty && v.hasOwnProperty('toString') && (typeof v.toString != 'undefined') && (obj.toString !== v.toString)) {
          obj.toString = v.toString;
        }
      }
   
      return obj;
    }
   
    function copyWhatever(obj) {
      obj = obj || {};
   
      if (window.__DEV__) {
        if (f) {
          throw new Error('Too many arguments passed to copyProperties');
        }
      }
   
      var args = arguments;
      var ii = 1,
          v;
      while (args[ii]) {
        v = args[ii++];
        for (var k in v) {
          obj[k] = v[k];
        }
   
        if (v.hasOwnProperty && v.hasOwnProperty('toString') && (typeof v.toString != 'undefined') && (obj.toString !== v.toString)) {
          obj.toString = v.toString;
        }
      }
   
      return obj;
    }
   
   
    var o = {
      name: "Kirk",
      family: "Hammet",
      plays: function() {
        return "mewawwwyee";
      }
    };
   
    var a = {aa:1,ab:2,ac:3};
    var b = {ab:1,bb:2,bc:3};
    var c = {ca:1,cb:2,cc:3};
    var d = {da:1,db:2,dc:3};
    var e = {ea:1,eb:2,ec:3};
   
};
</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
five_one
copyFive(o, a);
pending…
arg_one
copyWhatever(o, a);
pending…
five_five
copyFive(o,a,b,c,d,e);
pending…
args_five
copyWhatever(o,a,b,c,d,e);
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