JavaScript performance comparison

Test case created by John-David Dalton


This is an Array#filter implementation from a recent 140bytes code golf entry. It's faster than native Array#filter when iterating over large sparse arrays because it doesn't use the length property to calculate when it should stop iterating.

Preparation code

Array.prototype.filter2 = function(
  a, //a function to test each value of the array against. Truthy values will be put into the new array and falsey values will be excluded from the new array
  b, // placeholder
  c, // placeholder
  d, // placeholder
  e // placeholder
) {
  c = this; // cache the array
  d = []; // array to hold the new values which match the expression
  for (e in c) // for each value in the array,
    ~~e + '' == e && e >= 0 && // coerce the array position and if valid,, c[e], +e, c) && // pass the current value into the expression and if truthy,
    d.push(c[e]); // add it to the new array
  return d // give back the new array
Benchmark.prototype.setup = function() {
    var array = [];
    array[200] = 'a';
    function callback(v) {
      return /\w+/.test(v);

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec

Compare results of other browsers


You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:


John-David Dalton (revision owner) commented :

So Opera 12.00 is like whoa!? :D

fearphage commented :

Opera Mobile beat the desktops on native.

var me = 'impressed';

Add a comment