Skip to content

One-click benchmark runner script #7725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ docs/downloads
docs/vendor/bundle
examples/shared/*.js
examples/**/bundle.js
scripts/bench/arena
test/the-files-to-test.generated.js
*.log*
chrome-user-data
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"object-assign": "^4.1.0",
"platform": "^1.1.0",
"run-sequence": "^1.1.4",
"shelljs": "^0.7.4",
"through2": "^2.0.0",
"tmp": "~0.0.28",
"typescript": "~1.8.10",
Expand Down
7 changes: 7 additions & 0 deletions scripts/bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ Work-in-progress benchmarks.

## Running the suite

### One-click benchmark runner
```
./scripts/bench/benchmark-runner [--dev]
```
It takes bundles from your local `build` folder and compares them with React's latest master build (from http://react.zpao.com/builds/master/latest/). Notice that it doesn't build React by default; you can run `npm run build` manually before invoking the benchmark runner (like `npm run build && ./scripts/bench/benchmark-runner`).

### Run the suite manually
You'll need two folders to compare, each of them containing `react.min.js` and `react-dom-server.min.js`. You can run `npm run build` at the repo root to get a `build` folder with these files.

For example, if you want to compare a stable verion against master, you can create folders called `build-stable` and `build-master` and use the benchmark scripts like this:
Expand Down
43 changes: 43 additions & 0 deletions scripts/bench/benchmark-runner
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env node
'use strict';

const shell = require('shelljs');
const path = require('path');

const benchRoot = __dirname;
const projectRoot = path.resolve(benchRoot, '../..');
const arenaRoot = path.resolve(benchRoot, 'arena');

const __DEV__ = process.argv[2] === '--dev';

const files = __DEV__ ?
['react.js', 'react-dom-server.js'] :
['react.min.js', 'react-dom-server.min.js'];

function cleanUp() {
shell.rm('-rf', arenaRoot);
shell.mkdir(arenaRoot);
}

cleanUp();

shell.mkdir(path.join(arenaRoot, 'build-latest-master'));
files.forEach((name) => {
shell.exec(
`wget http://react.zpao.com/builds/master/latest/${name}`,
{cwd: path.join(arenaRoot, 'build-latest-master')}
);
});

shell.mkdir(path.join(arenaRoot, 'build-test'));
shell.cp(
files.map((name) => path.join(projectRoot, 'build', name)),
path.join(arenaRoot, 'build-test')
);

shell.exec([
`DEV=${__DEV__} ./measure.py arena/build-latest-master arena/master.txt arena/build-test arena/test.txt && `,
'./analyze.py arena/master.txt arena/test.txt',
].join(''), {cwd: benchRoot});

cleanUp();
11 changes: 7 additions & 4 deletions scripts/bench/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@ def _run_js_in_node(js, env):


def _measure_ssr_ms(engine, react_path, bench_name, bench_path, measure_warm):
react_core_path = "%s/%s" % (react_path, "react.js" if os.environ["DEV"] == "true" else "react.min.js")
react_dom_path = "%s/%s" % (react_path, "react-dom-server.js" if os.environ["DEV"] == "true" else "react-dom-server.min.js")

return engine(
"""
var reactCode = readFile(ENV.react_path + '/react.min.js');
var reactDOMServerCode = readFile(ENV.react_path + '/react-dom-server.min.js');
var reactCode = readFile(ENV.react_core_path);
var reactDOMServerCode = readFile(ENV.react_dom_path);
var START = now();
globalEval(reactCode);
globalEval(reactDOMServerCode);
Expand Down Expand Up @@ -112,7 +115,8 @@ def _measure_ssr_ms(engine, react_path, bench_name, bench_path, measure_warm):
'bench_name': bench_name,
'bench_path': bench_path,
'measure_warm': measure_warm,
'react_path': react_path,
'react_core_path': react_core_path,
'react_dom_path': react_dom_path,
},
)

Expand Down Expand Up @@ -172,4 +176,3 @@ def _main():

if __name__ == '__main__':
sys.exit(_main())