list all

JavaScript performance comparison

Test case created by Carlos Vázquez

Preparation code

<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.23.0/ramda.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>

      
<script>
Benchmark.prototype.setup = function() {
  function all(f, lst) {
      for (var i = 0, le = lst.length; i < le; i++) {
          if (!f(lst[i])) return false;
      }
      return true;
  }
  function allCurried(f, lst) {
      if (lst === undefined) {
          return all.bind(this, f);
      }
      return all(f, lst);
  };
  
  var ramdaAll = R.all;
  var lodashAll = _.every;
  
  var le = 10000,
      a = Array(le);
  
  for(var i = 0; i < le; i++){
      a[i] = Math.random() * 2 - 1;
  }
  
  function positive(n) {
      return n > 0;
  }
  function nonPositive(n) {
      return n <= 0;
  }

};
</script>

Preparation code output

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>

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
Hand made
all(positive, a)
pending…
Curried hand made
allCurried(positive)(a)
pending…
Native
!a.some(nonPositive)
pending…
Lodash
lodashAll(a, positive)
pending…
Ramda
ramdaAll(positive)(a)
pending…
Curried hand made non curying
allCurried(positive, a)
pending…
Ramda non curried
ramdaAll(positive, a)
pending…

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

0 Comments