_.includes vs object lookup

JavaScript performance comparison

Test case created by Brian Turgeon

Preparation code

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
      
<script>
Benchmark.prototype.setup = function() {
  let arr5 = Array.apply(null, {length: 5}).map(Number.call, Number);
  let arr100 = Array.apply(null, {length: 100}).map(Number.call, Number);
  let arr1000 = Array.apply(null, {length: 1000}).map(Number.call, Number);
  let obj5 = obj100 = obj1000 = {};
  arr5.forEach((num) => { obj5['val' + num] = true });
  arr100.forEach((num) => { obj100['val' + num] = true });
  arr1000.forEach((num) => { obj1000['val' + num] = true });
  

};
</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
lodash 5
let isTrue = _.includes(arr5, 3);
pending…
object lookup 5
let isTrue = obj5.val3;
pending…
lodash 1000
let isTrue = _.includes(arr1000, 3);
pending…
lodash 100
let isTrue = _.includes(arr100, 3);
pending…
object lookup 100
let isTrue = obj100.val3;
pending…
object lookup 1000
let isTrue = obj1000.val3;
pending…

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

0 Comments