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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const THRESHOLD = 0.2
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-03-21 22:32:14 -07:00
|
|
|
const b = base.iterations / base.elapsed * 100
|
|
|
|
const c = comp.iterations / comp.elapsed * 100
|
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)
|
|
|
|
|
|
|
|
let output = `${b.toFixed(2)} --> ${c.toFixed(2)} iterations/sec`
|
|
|
|
if (slower) output = chalk.red(`${output} (${percent}% slower)`)
|
|
|
|
if (faster) output = chalk.green(`${output} (${percent}% faster)`)
|
|
|
|
|
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()
|