2017-03-21 17:38:39 -07:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
|
|
|
|
import chalk from 'chalk'
|
2017-03-21 22:32:14 -07:00
|
|
|
import baseline from '../tmp/benchmark-baseline'
|
|
|
|
import comparison from '../tmp/benchmark-comparison'
|
2017-03-21 17:38:39 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constants.
|
|
|
|
*/
|
|
|
|
|
2017-10-26 14:46:34 -07:00
|
|
|
const THRESHOLD = 0.333
|
2017-03-21 17:38:39 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Print.
|
|
|
|
*/
|
|
|
|
|
2017-03-21 22:32:14 -07:00
|
|
|
console.log()
|
|
|
|
console.log(` benchmarks`)
|
|
|
|
|
2017-03-21 17:38:39 -07:00
|
|
|
baseline.forEach((suite, i) => {
|
2017-03-21 22:32:14 -07:00
|
|
|
console.log(` ${suite.name}`)
|
2017-03-21 17:38:39 -07:00
|
|
|
|
|
|
|
suite.benchmarks.forEach((base, j) => {
|
|
|
|
const comp = comparison[i].benchmarks[j]
|
2017-04-02 14:57:36 -07:00
|
|
|
if (!comp) return
|
|
|
|
|
2017-10-26 14:46:34 -07:00
|
|
|
const b = base.iterations / base.elapsed * 1000
|
|
|
|
const c = comp.iterations / comp.elapsed * 1000
|
2017-03-21 17:38:39 -07:00
|
|
|
const threshold = b * THRESHOLD
|
|
|
|
const slower = (b - c) > threshold
|
|
|
|
const faster = (b - c) < (0 - threshold)
|
|
|
|
const percent = Math.round(Math.abs(b - c) / b * 100)
|
|
|
|
|
2017-10-26 14:46:34 -07:00
|
|
|
let output = `${b.toFixed(2)} → ${c.toFixed(2)} ops/sec`
|
2017-03-21 17:38:39 -07:00
|
|
|
if (slower) output = chalk.red(`${output} (${percent}% slower)`)
|
2017-05-05 11:45:19 -07:00
|
|
|
else if (faster) output = chalk.green(`${output} (${percent}% faster)`)
|
|
|
|
else output = chalk.gray(output)
|
|
|
|
|
|
|
|
if (percent > 1000) output += ' 😱'
|
|
|
|
else if (faster && percent > 100) output += ' 🙌'
|
|
|
|
else if (slower && percent > 100) output += ' 😟'
|
2017-03-21 17:38:39 -07:00
|
|
|
|
2017-03-21 22:32:14 -07:00
|
|
|
console.log(` ${base.title}`)
|
|
|
|
console.log(` ${output}`)
|
2017-03-21 17:38:39 -07:00
|
|
|
})
|
|
|
|
})
|
2017-03-21 22:32:14 -07:00
|
|
|
|
|
|
|
console.log()
|