allprops

JavaScript performance comparison

Test case created by

Preparation code

<div id="me" rel="you" class="test"><span>what?</span></div>

<a class="test" data-id="one"></a>

<script src="https://ajax.googleapis.com/ajax/libs/mootools/1.4.5/mootools-yui-compressed.js"></script>

      
<script>
Benchmark.prototype.setup = function() {
  Element.implement({
      allProperties1: function(){
          var j = {};
          Array.each(this.attributes, function(attr){
              var n= {};
              n[attr.nodeName] = attr.nodeValue;
              Object.append(j, n);
          });
          Object.append(j,{text: this.get('text')});
          Object.append(j,{html: this.get('html')});
          return j;
      },
      allProperties2: function(){
          for (var attr, j = this.get(["text","html"]), i = 0, len = this.attributes.length; i < len; ++i) {
             attr = this.attributes[i];
             j[attr['nodeName']] = attr['nodeValue'];
          };        
          return j;
      }
  });
  

};
</script>

Preparation code output

<div id="me" rel="you" class="test"><span>what?</span></div> <a class="test" data-id="one"></a>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
original
document.id('me').allProperties1();
document.getElements('.test').allProperties1();
pending…
optimised
document.id('me').allProperties2();
document.getElements('.test').allProperties2();
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

what?