inArray map vs possibly native

Benchmark created by Mike McCaughan on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
  var dr = {};
  dr.utility = {};
  dr.utility.hasEvery = typeof Array.prototype.every !== 'undefined';
  dr.utility.hasSome = typeof Array.prototype.some !== 'undefined';
  dr.utility.any = function (arr, fn) { return $.inArray(true, $.map(arr, fn)) > 0; };
  dr.utility.anySome = function (arr, fn) { return $.isArray(arr) && dr.utility.hasSome ? arr.some(fn) : dr.utility.any(arr, fn); };
  dr.utility.all = function (arr, fn) { return $.inArray(false, $.map(arr, fn)) > 0; };
  dr.utility.allEvery = function (arr, fn) { return $.isArray(arr) && dr.utility.hasEvery ? arr.every(fn) : dr.utility.all(arr, fn); };
  var isGreaterThanOne = function (value) { return value > 1; };
  var testArray = [];
  for (var i = 0; i < 10000; i++) {
  testArray.push(Math.random() * (Math.random() + 1));
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
All
var gotOne = dr.utility.all(testArray, isGreaterThanOne);
ready
Every
var gotOne = dr.utility.allEvery(testArray, isGreaterThanOne);
ready
Any
var gotOne = dr.utility.any(testArray, isGreaterThanOne);
ready
Some
var gotOne = dr.utility.anySome(testArray, isGreaterThanOne);
ready

Revisions

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

  • Revision 1: published by Mike McCaughan on