forked from milomg/js-reactivity-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 2
/
dynamicBench.ts
37 lines (31 loc) · 1.18 KB
/
dynamicBench.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
import { makeGraph, runGraph } from "./util/dependencyGraph";
import { logPerfResult, perfRowStrings } from "./util/perfLogging";
import { verifyBenchResult } from "./util/perfTests";
import { FrameworkInfo } from "./util/frameworkTypes";
import { perfTests } from "./config";
import { fastestTest } from "./util/benchRepeat";
/** benchmark a single test under single framework.
* The test is run multiple times and the fastest result is logged to the console.
*/
export async function dynamicBench(
frameworkTest: FrameworkInfo,
testRepeats = 1
): Promise<void> {
const { framework } = frameworkTest;
for (const config of perfTests) {
const { iterations, readFraction } = config;
const { graph, counter } = makeGraph(framework, config);
function runOnce(): number {
return runGraph(graph, iterations, readFraction, framework);
}
// warm up
// runOnce();
const timedResult = await fastestTest(testRepeats, () => {
counter.count = 0;
const sum = runOnce();
return { sum, count: counter.count };
});
logPerfResult(perfRowStrings(framework.name, config, timedResult));
verifyBenchResult(frameworkTest, config, timedResult);
}
}