Benchmarkjs : a very small tool to compare speed

Wanting to quickly figure out which way is the fastest ?

Want to see median times in µs ?

Download that module :

And call benchmark that way : (copy/paste that code, change ‘forThisWork’ – what to measure, ‘theContestants ‘- who to measure, and ‘seedInit’ – what data should it use)

     {naive: seed => seed.reduce((max, value) => max > value ? max : value, 0),
      iterative: seed => {let max = seed[0]; for (let index = 1 ; index < seed.length ; index++) max = Math.max(max, seed[index])},
      sorted: seed => seed.slice().sort().slice(-1)[0]},
    forThisWork: (max, seed) => max(seed),
    howManyTimes: 1000,
    seedInit: () => new Array(500).fill(Math.random() * 10000),
    barSettings: {width: 100.0, gradient: ['\x1B[47m', '\x1B[42m', '\x1B[46m', '\x1B[45m', '\x1B[41m']},
    asText: true, logInConsole: true})

You will see this kind of graph :


Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.