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 : https://gist.github.com/libetl/952e026f889be1cc7cdb3b42767ea845

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)

benchmark({theContestants: 
     {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 :

benchmark

Leave a Reply

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

*