@samitouri / QOS-React-2 / commits / 3fcba2044a

Fix benchmarks (#7704)

Dan Abramov committed Sep 12, 2016 at 21:58 UTC 3fcba2044af17ac309c21dbc88e814a94245987b
2 files changed +21 -6
scripts/bench/README.md
+12 -2
@@ -2,11 +2,21 @@ Work-in-progress benchmarks.
2
3 ## Running the suite
4
5 +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.
6 +
7 +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:
8 +
9 ```
6 -$ ./measure.py react-a.min.js a.txt react-b.min.js b.txt
7 -$ ./analyze.py a.txt b.txt
10 +$ ./measure.py build-stable stable.txt build-master master.txt
11 +$ ./analyze.py stable.txt master.txt
12 ```
13
14 +The test measurements (second argument to `analyze`, `master.txt` in this example) will be compared to the control measurements (first argument to `analyze`, `stable.txt` in this example).
15 +
16 +Changes with the `-` sign in the output mean `master` is faster than `stable`.
17 +
18 +You can name folders any way you like, this was just an example.
19 +
20 ## Running one
21 One thing you can do with them is benchmark initial render time for a realistic hierarchy:
22
scripts/bench/measure.py
+9 -4
@@ -73,12 +73,14 @@ def _run_js_in_node(js, env):
73 def _measure_ssr_ms(engine, react_path, bench_name, bench_path, measure_warm):
74 return engine(
75 """
76 - var reactCode = readFile(ENV.react_path);
76 + var reactCode = readFile(ENV.react_path + '/react.min.js');
77 + var reactDOMServerCode = readFile(ENV.react_path + '/react-dom-server.min.js');
78 var START = now();
79 globalEval(reactCode);
80 + globalEval(reactDOMServerCode);
81 var END = now();
80 - ReactDOMServer = React.__SECRET_DOM_SERVER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED || React;
81 - if (typeof React !== 'object') throw new Error('React not laoded');
82 + if (typeof React !== 'object') throw new Error('React not loaded');
83 + if (typeof ReactDOMServer !== 'object') throw new Error('ReactDOMServer not loaded');
84 report('factory_ms', END - START);
85
86 globalEval(readFile(ENV.bench_path));
@@ -117,7 +119,7 @@ def _measure_ssr_ms(engine, react_path, bench_name, bench_path, measure_warm):
119
120 def _main():
121 if len(sys.argv) < 2 or len(sys.argv) % 2 == 0:
120 - sys.stderr.write("usage: measure.py react.min.js out.txt react2.min.js out2.txt\n")
122 + sys.stderr.write("usage: measure.py build-folder-a a.txt build-folder-b b.txt\n")
123 return 1
124 # [(react_path, out_path)]
125 react_paths = sys.argv[1::2]
@@ -142,7 +144,10 @@ def _main():
144 sys.stderr.write("\n")
145 sys.stderr.flush()
146
147 + # You can set this to a number of trials you want to do with warm JIT.
148 + # They are disabled by default because they are slower.
149 trials = 0
150 +
151 sys.stderr.write("Measuring SSR for PE with warm JIT (%d slow trials)\n" % trials)
152 sys.stderr.write("_" * trials + "\n")
153 for i in range(trials):