Arrayification

Benchmark created by Mathias Bynens on


Preparation HTML

<script>
  Array.fy = (function() {
   // © WebReflection — MIT-style license
   for (var
    m = [
     'pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift',
     'concat', 'join', 'slice', 'indexOf', 'lastIndexOf',
     'filter', 'forEach', 'every', 'map', 'some', 'reduce', 'reduceRight'
    ],
    i = m.length;
    i--;
   ) {
    m[i] = 'o.' + m[i] + '=p.' + m[i];
   }
   m.push('return o');
   return Function('p',
    'return function Arrayfy(o){' + m.join(';') + '}'
   )(Array.prototype);
  }());
  
  var slice = Array.prototype.slice,
      args = [1, 2, 3, 4, 5],
      fy = Array.fy,
      forEach = Array.prototype.forEach,
      forEachGeneric = Array.forEach,
      callback = function() { };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Array.fy(arguments).forEach
(function() {
 fy(arguments).forEach(callback);
}).apply(null, args);
ready
slice.call(arguments).forEach
(function() {
 slice.call(arguments).forEach(callback);
}).apply(null, args);
ready
arguments.__proto__ = Array.prototype; arguments.forEach
(function() {
 arguments.__proto__ = Array.prototype;
 arguments.forEach(callback);
}).apply(null, args);
ready
Array.prototype.forEach.call(arguments)
(function() {
 forEach.call(arguments, callback);
}).apply(null, args);
ready
Array.apply(null, arguments).forEach
(function(){
 Array.apply(null, arguments).forEach(callback);
}).apply(null, args);
ready
Array.forEach(arguments)
(function(){
 forEachGeneric(arguments, callback);
}).apply(null, args);
ready

Revisions

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

  • Revision 1: published by Mathias Bynens on