Created
August 14, 2016 01:03
-
-
Save zertosh/e05e708262ee499626fc4998646c79a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
'use strict'; | |
// npm install stats-lite | |
// export PATH="/System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/Resources:$PATH" | |
// ./node_modules/.bin/grunt build | |
// node load-benchmark.js | |
const {spawnSync} = require('child_process'); | |
const stats = require('stats-lite'); | |
const runs = [ | |
{engine: 'node', NODE_ENV: 'development', build: 'react.js'}, | |
{engine: 'node', NODE_ENV: 'production', build: 'react.js'}, | |
{engine: 'node', build: 'dist/react-with-addons.js'}, | |
{engine: 'node', build: 'dist/react-with-addons.min.js'}, | |
{engine: 'node', build: 'dist/react.js'}, | |
{engine: 'node', build: 'dist/react.min.js'}, | |
{engine: 'jsc', build: 'dist/react-with-addons.js'}, | |
{engine: 'jsc', build: 'dist/react-with-addons.min.js'}, | |
{engine: 'jsc', build: 'dist/react.js'}, | |
{engine: 'jsc', build: 'dist/react.min.js'}, | |
]; | |
runs.map(trial => { | |
const {engine, build, NODE_ENV} = trial; | |
const times = Array(100).fill().map(() => { | |
const ps = spawnSync(engine, ['-e', ` | |
if (typeof require === 'undefined') require = load; | |
if (typeof console === 'undefined') console = {log: print}; | |
var t1 = Date.now(); | |
require('./build/packages/react/${build}'); | |
var t2 = Date.now(); | |
console.log(t2 - t1); | |
`], { | |
env: Object.assign({}, process.env, {NODE_ENV}) | |
}); | |
return parseInt(ps.stdout); | |
}); | |
trial.mean = stats.mean(times); | |
trial.p90 = stats.percentile(times, 0.90); | |
trial.p95 = stats.percentile(times, 0.95); | |
}); | |
console.log('| engine | build | avg / p90 (ms) |'); | |
console.log('| ------ | ----- | -------------: |'); | |
runs.forEach(({engine, build, NODE_ENV, mean, p90}) => { | |
console.log( | |
'| %s | %s | %s |', | |
engine, | |
NODE_ENV ? `${build} (${NODE_ENV})` : build, | |
`${mean.toFixed(2)} / ${p90}` | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment