Created
March 10, 2019 14:52
-
-
Save starkwang/a5045f3d50ae2f1326eea50d4f8267e1 to your computer and use it in GitHub Desktop.
benchmark for Array#includes and Array#indexOf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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