Array Filter

Benchmark created by Derek on


Preparation HTML

<div id="1" class="buttsecks"></div>
<div id="2" class="buttsecks"></div>
<div id="3" class="buttsecks"></div>
<div id="4" class="buttsecks"></div>
<div id="5" class="buttsecks"></div>
<div id="6" class="buttsecks"></div>
<div id="7" class="buttsecks"></div>
<script>
  String.prototype.contains = function(word) {
   return (this !== '' && (' ' + this + ' ').indexOf(' ' + word + ' ') + 1);
  };
  
  function Query(k, v, f) {
   var i = this.length,
       j = i,
       r = new Array(i);
   while (--i >= 0) {
    if (f && f.call(this[i][k], v) || this[i][k] === v) r[--j] = this[i];
   }
   return r.slice(j);
  }
  
  
  var all = document.all || document.getElementsByTagName('*');
  var id = 'buttsecks';
  var e;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Query Custom
e = Query.call(all, 'className', id, String.prototype.contains);
ready
Filter
e = Array.prototype.filter.call(all, (function(el, index, array) {
 return el['className'].contains(id);
}));
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.