forked from rocicorp/replicache
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.mjs
More file actions
60 lines (49 loc) · 1.53 KB
/
Copy pathrunner.mjs
File metadata and controls
60 lines (49 loc) · 1.53 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
// @ts-check
/* eslint-env node, es2020 */
import playwright from 'playwright';
import {startDevServer} from '@web/dev-server';
import getPort from 'get-port';
async function main() {
const verbose = process.argv.includes('--verbose');
const port = await getPort();
const server = await startDevServer({
config: {
rootDir: process.cwd(),
port,
watch: false,
},
readCliArgs: false,
readFileConfig: false,
logStartMessage: verbose,
});
const browserType = 'chromium';
const browser = await playwright[browserType].launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.goto(`http://127.0.0.1:${port}/perf/index.html`);
await page.waitForFunction('typeof nextTest === "function"');
logLine('Running benchmarks please wait...');
for (;;) {
const testResult = await page.evaluate('nextTest()');
if (testResult === null) {
break;
}
logLine(formatAsBenchmarkJS(testResult));
}
logLine('Done!');
await browser.close();
await server.stop();
}
main();
/** @param {string} s */
function logLine(s) {
process.stdout.write(s + '\n');
}
// TODO(arv): Use BenchmarkJS instead of our custom runner?
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function formatAsBenchmarkJS({name, value, median}) {
// Example:
// fib(20) x 11,465 ops/sec ±1.12% (91 runs sampled)
// createObjectBuffer with 200 comments x 81.61 ops/sec ±1.70% (69 runs sampled)
return `${name} x ${value} ±0.0% (0 runs sampled)`;
}