Skip to content

Commit 7774c86

Browse files
committed
feat: calculate the average HMR time
1 parent ed7f51a commit 7774c86

File tree

2 files changed

+22
-36
lines changed

2 files changed

+22
-36
lines changed

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ Benchmark comparing JavaScript bundlers and build tools ([Rspack](https://github
44

55
## Metrics
66

7-
| Name | Description | Notes |
8-
| ------------------ | ----------------------------------------------- | ----------------------------------------- |
9-
| **Dev cold start** | Total time from dev server start to page loaded | Equals to `server start` + `page load` |
10-
| **Server start** | Time taken for the dev server to start | Includes initial build for loaded modules |
11-
| **Page load** | Time to load the page after server is ready | |
12-
| **Root HMR** | Time to HMR after changing a root module | |
13-
| **Leaf HMR** | Time to HMR after changing a leaf module | |
14-
| **Prod build** | Time taken to build the production bundles | |
15-
| **Total size** | Total size of the bundle | Minified by the default minifier |
16-
| **Gzipped size** | Gzipped size of the bundle | Represents actual network transfer size |
7+
| Name | Description | Notes |
8+
| ------------------ | ----------------------------------------------- | -------------------------------------------------- |
9+
| **Dev cold start** | Total time from dev server start to page loaded | Equals to `server start` + `page load` |
10+
| **Server start** | Time taken for the dev server to start | Includes initial build for loaded modules |
11+
| **Page load** | Time to load the page after server is ready | |
12+
| **HMR** | Time to HMR after changing a module | Average time to update root module and leaf module |
13+
| **Prod build** | Time taken to build the production bundles | |
14+
| **Total size** | Total size of the bundle | Minified by the default minifier |
15+
| **Gzipped size** | Gzipped size of the bundle | Represents actual network transfer size |
1716

1817
## Notes
1918

benchmark.mjs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,15 @@ async function runDevBenchmark(buildTool, perfResult) {
391391
let hmrLeafStart = -1;
392392

393393
page.on('console', (event) => {
394-
const isFinished = () => {
395-
return (
396-
perfResult[buildTool.name]?.rootHmr &&
397-
perfResult[buildTool.name]?.leafHmr
398-
);
394+
const afterHMR = () => {
395+
const currentResult = perfResult[buildTool.name];
396+
if (currentResult?.rootHmr && currentResult?.leafHmr) {
397+
currentResult.hmr = (currentResult.rootHmr + currentResult.leafHmr) / 2;
398+
page.close();
399+
waitResolve();
400+
}
399401
};
402+
400403
if (event.text().includes('root hmr')) {
401404
const match = /(\d+)/.exec(event.text());
402405
if (!match) {
@@ -412,10 +415,7 @@ async function runDevBenchmark(buildTool, perfResult) {
412415
);
413416

414417
perfResult[buildTool.name].rootHmr = hmrTime;
415-
if (isFinished()) {
416-
page.close();
417-
waitResolve();
418-
}
418+
afterHMR();
419419
} else if (event.text().includes('leaf hmr')) {
420420
const hmrTime = Date.now() - hmrLeafStart;
421421
logger.success(
@@ -424,10 +424,7 @@ async function runDevBenchmark(buildTool, perfResult) {
424424
color.green(hmrTime + 'ms'),
425425
);
426426
perfResult[buildTool.name].leafHmr = hmrTime;
427-
if (isFinished()) {
428-
page.close();
429-
waitResolve();
430-
}
427+
afterHMR();
431428
}
432429
});
433430

@@ -644,29 +641,19 @@ if (runDev) {
644641
averageResults,
645642
'devColdStart',
646643
);
647-
const rootHmrRanked = addRankingEmojis(
648-
actualToolNames,
649-
averageResults,
650-
'rootHmr',
651-
);
652-
const leafHmrRanked = addRankingEmojis(
653-
actualToolNames,
654-
averageResults,
655-
'leafHmr',
656-
);
644+
const hmrRanked = addRankingEmojis(actualToolNames, averageResults, 'hmr');
657645
const prodBuildRanked = addRankingEmojis(
658646
actualToolNames,
659647
averageResults,
660648
'prodBuild',
661649
);
662650

663651
markdownLogs += markdownTable([
664-
['Name', 'Dev cold start', 'Root HMR', 'Leaf HMR', 'Prod build'],
652+
['Name', 'Dev cold start', 'HMR', 'Prod build'],
665653
...actualToolNames.map((name) => [
666654
name,
667655
`${devColdStartRanked[name]} (${averageResults[name].serverStart.replace('ms', '')} + ${averageResults[name].onLoad.replace('ms', '')})`,
668-
rootHmrRanked[name],
669-
leafHmrRanked[name],
656+
hmrRanked[name],
670657
prodBuildRanked[name],
671658
]),
672659
]);

0 commit comments

Comments
 (0)