-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.ts
54 lines (47 loc) · 1.53 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { InitialRenderBenchmark, Runner } from "@tracerbench/core";
import * as networkEmulationConditions from "network-emulation-conditions";
import * as fs from "fs-extra";
const config: {
runCount: number;
networkCondition: string;
cpuThrottleRate: number;
servers: Array<{ name: string; port: number; networkCondition: string }>;
} = JSON.parse(fs.readFileSync("config.json", "utf8"));
let benchmarks = config.servers.map(({ name, port }) => {
let options = {
name,
url: `http://localhost:${port}/?perf.tracing`,
markers: [
{ start: "domLoading", label: "load" },
{ start: "beforeVendor", label: "boot" },
{ start: "willTransition", label: "transition" },
{ start: "didTransition", label: "render" }
],
runtimeStats: false
};
let networkConditions = networkEmulationConditions[config.networkCondition];
if (networkConditions) {
options["networkConditions"] = {
offline: false,
latency: networkConditions.latency,
downloadThroughput: networkConditions.download,
uploadThroughput: networkConditions.upload
};
}
if (config.cpuThrottleRate) {
options["cpuThrottleRate"] = config.cpuThrottleRate;
}
return new InitialRenderBenchmark(options);
});
fs.emptyDir("./results")
.then(() => {
let runner = new Runner(benchmarks);
return runner.run(config.runCount);
})
.then(results => {
fs.writeFileSync("results/results.json", JSON.stringify(results, null, 2));
})
.catch(err => {
console.error(err.stack);
process.exit(1);
});