-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathbenchmark.js
More file actions
60 lines (50 loc) · 1.67 KB
/
benchmark.js
File metadata and controls
60 lines (50 loc) · 1.67 KB
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
55
56
57
58
59
60
globalThis.console = {
log() { },
warn() { },
assert(condition) {
if (!condition) throw new Error("Invalid assertion");
}
};
globalThis.clearTimeout = function () { };
// JetStream benchmark.
class Benchmark extends StartupBenchmark {
// How many times (separate iterations) should we reuse the source code.
// Use 0 to skip.
lastResult = {};
sourceHash = 0
constructor({iterationCount}) {
super({
iterationCount,
expectedCacheCommentCount: 597,
sourceCodeReuseCount: 1,
});
}
runIteration(iteration) {
// super.prepareForNextIteration() sets this up for us.
let sourceCode = this.currentIterationSourceCode;
if (!sourceCode)
throw new Error(`Could not find source for iteration ${iteration}`);
// Module in sourceCode it assigned to the ReactRenderTest variable.
let ReactRenderTest;
let initStart = performance.now();
const res = eval(sourceCode);
const runStart = performance.now();
this.lastResult = ReactRenderTest.renderTest();
this.lastResult.htmlHash = this.quickHash(this.lastResult.html);
const end = performance.now();
const loadTime = runStart - initStart;
const runTime = end - runStart;
// For local debugging:
// print(`Iteration ${iteration}:`);
// print(` Load time: ${loadTime.toFixed(2)}ms`);
// print(` Render time: ${runTime.toFixed(2)}ms`);
}
validate() {
this.expect("HTML length", this.lastResult.html.length, 183778);
this.expect("HTML hash", this.lastResult.htmlHash, 1177839858);
}
expect(name, value, expected) {
if (value != expected)
throw new Error(`Expected ${name} to be ${expected}, but got ${value}`);
}
}