Performance test for comparing string with multiple string

node v6.17.1
version: master
endpointsharetweet
const now = require('performance-now'); function strTest(str){ return (str === 'something' || str === 'nothing' || str === 'anything' || str === 'everything'); } function strTestExp(str){ return str.match(/^(something|nothing|anything|everything)$/) !== null; } function strTestArray(str){ return (['something', 'nothing', 'anything', 'everything'].indexOf(str) > -1); } const performanceTest = (callback) => { const t0 = now(); callback(); const t1 = now(); console.log(callback.toString(), `took ${(t1 - t0)} milliseconds.`); }; performanceTest(() => { strTest('nothing'); }); performanceTest(() => { strTestExp('nothing'); }); performanceTest(() => { strTestArray('nothing'); });
Loading…

no comments

    sign in to comment