Skip to content

Instantly share code, notes, and snippets.

@starkwang
Created March 10, 2019 14:52
Show Gist options
  • Save starkwang/a5045f3d50ae2f1326eea50d4f8267e1 to your computer and use it in GitHub Desktop.
Save starkwang/a5045f3d50ae2f1326eea50d4f8267e1 to your computer and use it in GitHub Desktop.
benchmark for Array#includes and Array#indexOf
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
var items = [
"jpg", "3fr",
"ari", "arw",
"bay",
"crw", "cr2",
"cap",
"data", "dcs", "dcr", "dng",
"drf",
"eip", "erf",
"fff",
"iiq",
"k25", "kdc",
"mdc", "mef", "mos", "mrw",
"nef", "nrw",
"obm", "orf",
"pef", "ptx", "pxn",
"r3d", "raf", "raw", "rwl", "rw2", "rwz",
"sr2", "srf", "srw",
"tif",
"x3f"
];
suite
.add('Array#indexOf', function () {
items.indexOf('raf') !== -1
})
.add('Array#includes', function () {
items.includes('raf')
})
.on('cycle', function (event) {
console.log(String(event.target));
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ 'async': true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment