const obj = { abs: true, acos: true, acosh: true, asin: true, asinh: true, atan: true, atan2: true, atanh: true, cbrt: true, ceil: true, clz32: true, cos: true, cosh: true, expm1: true, exp: true, floor: true, fround: true, imul: true, log: true, log2: true, log10: true, log1p: true, max: true, min: true, pow: true, random: true, round: true, sign: true, sin: true, sinh: true, sqrt: true, tan: true, tanh: true, trunc: true, }; const arr = Object.keys(obj); const map = new Map(); arr.forEach(val => map.set(val, true)); function findArrIncludes(find) { return arr.includes(find); } function findArrIndexOf(find) { return arr.indexOf(find) > -1; } function findObj(find) { return !!obj[find]; } function findMap(find) { return map.has(find); } const END_ELEM = arr[arr.length - 1]; const FIRST_ELEM = arr[0]; const MIDDLE_ELEM = arr[Math.floor(arr.length / 2)] function bench(fn, suffix, elem) { const t = new Date().getTime(); for (let i = 0; i < 1e9; i++) { fn(elem); } console.log(fn.name + suffix, new Date().getTime() - t, 'ms'); } function benchaddo(fn) { bench(fn, '_first', FIRST_ELEM); bench(fn, '_middle', MIDDLE_ELEM); bench(fn, '_end', END_ELEM); } // benchaddo(findArrIndexOf); // benchaddo(findArrIncludes); benchaddo(findObj); // benchaddo(findMap);