2017-03-21 17:38:39 -07:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
|
|
|
|
import chalk from 'chalk'
|
2018-07-19 16:01:55 -04:00
|
|
|
import figures from 'figures'
|
|
|
|
import emojis from 'emojis'
|
2018-02-06 19:41:03 -08:00
|
|
|
import baseline from '../../tmp/benchmark-baseline'
|
|
|
|
import comparison from '../../tmp/benchmark-comparison'
|
2018-07-19 16:01:55 -04:00
|
|
|
import { existsSync } from 'fs'
|
2017-03-21 17:38:39 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constants.
|
|
|
|
*/
|
|
|
|
|
2018-07-19 16:01:55 -04:00
|
|
|
let THRESHOLD = 0.333
|
|
|
|
const configPath = '../../tmp/benchmark-config.js'
|
|
|
|
if (existsSync(configPath)) {
|
|
|
|
const alternative = require(configPath).THRESHOLD
|
|
|
|
if (typeof alternative === 'number' && alternative > 0) {
|
|
|
|
THRESHOLD = alternative
|
|
|
|
}
|
|
|
|
}
|
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) => {
|
2018-07-19 16:01:55 -04:00
|
|
|
const compared = { user: {}, hr: {} }
|
|
|
|
|
|
|
|
for (const key of Object.keys(compared)) {
|
|
|
|
const comp = comparison[i].benchmarks[j]
|
|
|
|
if (!comp) return
|
|
|
|
const b = base.iterations / base[key] * 1000
|
|
|
|
const c = comp.iterations / comp[key] * 1000
|
|
|
|
const balancePercent =
|
|
|
|
b > c ? Math.round(Math.abs(b - c) / c * 100) : (c - b) / b * 100
|
|
|
|
|
|
|
|
const output = `${b.toFixed(2)} -> ${c.toFixed(2)} ops/sec`
|
|
|
|
compared[key].baseOutput = output
|
|
|
|
compared[key].percentOutput = `${balancePercent.toFixed(2)}% ${
|
|
|
|
c > b ? 'faster' : 'slower'
|
|
|
|
}`
|
|
|
|
compared[key].percentValue = balancePercent
|
|
|
|
compared[key].b = b
|
|
|
|
compared[key].c = c
|
|
|
|
compared[key].isFaster = c > b
|
|
|
|
if (balancePercent > 1000) {
|
|
|
|
compared[key].percentOutput += emojis.unicode(' :scream: ')
|
|
|
|
} else if (balancePercent > 100) {
|
|
|
|
if (c > b) {
|
|
|
|
compared[key].percentOutput += emojis.unicode(' :raised_hands: ')
|
|
|
|
} else {
|
|
|
|
compared[key].percentOutput += emojis.unicode(' :worried: ')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const { user, hr } = compared
|
|
|
|
|
|
|
|
if (
|
|
|
|
user.percentValue < THRESHOLD * 100 &&
|
|
|
|
hr.percentValue < THRESHOLD * 100
|
|
|
|
) {
|
|
|
|
console.log(
|
|
|
|
chalk.grey(
|
|
|
|
` ${figures.tick} ${base.name}: ${user.baseOutput} (${
|
|
|
|
user.percentOutput
|
|
|
|
})`
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user.isFaster === hr.isFaster) {
|
|
|
|
if (user.isFaster) {
|
|
|
|
console.log(chalk.green(` ${figures.star} ${base.name}:`))
|
|
|
|
console.log(
|
|
|
|
` user: ${user.baseOutput} (${user.percentOutput})`
|
|
|
|
)
|
|
|
|
console.log(` real: ${hr.baseOutput} (${hr.percentOutput})`)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
console.log(chalk.red(` ${figures.cross} ${base.name}:`))
|
|
|
|
console.log(
|
|
|
|
` user: ${user.baseOutput} (${user.percentOutput})`
|
|
|
|
)
|
|
|
|
console.log(` real: ${hr.baseOutput} (${hr.percentOutput})`)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(chalk.red(` ${figures.questionMarkPrefix} ${base.name}:`))
|
|
|
|
console.log(` user: ${user.baseOutput} (${user.percentOutput})`)
|
|
|
|
console.log(` real: ${hr.baseOutput} (${hr.percentOutput})`)
|
2017-03-21 17:38:39 -07:00
|
|
|
})
|
|
|
|
})
|
2017-03-21 22:32:14 -07:00
|
|
|
|
|
|
|
console.log()
|