Skip to content

Commit

Permalink
Add run tracking to hydrate benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewiggins committed Apr 3, 2023
1 parent ff54c49 commit 4b5e755
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions benches/src/hydrate1k.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
measureMemory,
testElementText,
afterFrame,
afterFrameAsync
afterFrameAsync,
markRunStart,
markRunEnd
} from './util.js';
import * as framework from 'framework';
import { getComponents } from '../src/keyed-children/components.js';
Expand Down Expand Up @@ -101,17 +103,20 @@
testElementText(lastRowSel, '1000');
await clickRemove(hydrateRoot, `WARMUP ${i} - prehydrate`, 1000, 1000);

// Hydrate the root
const store = new Store();
store.data = baseStore.data.slice();
markRunStart(`warmup-${i}`);
createRoot(hydrateRoot).hydrate(createElement(Main, { store }));
await markRunEnd(`warmup-${i}`);

// Verify hydrate has correct markup and is properly hydrated
testElementText(firstRowSel, '1');
testElementText(lastRowSel, '1000');
await clickRemove(hydrateRoot, `WARMUP ${i} - posthydrate`, 1000, 999);
}

function timedRun() {
async function timedRun() {
afterFrame(function () {
performance.mark('stop');
performance.measure(measureName, 'start', 'stop');
Expand All @@ -123,20 +128,21 @@
const store = new Store();
store.data = baseStore.data.slice();

markRunStart('final');
performance.mark('start');
createRoot(hydrateRoot).hydrate(createElement(Main, { store }));
await markRunEnd('final');
}

async function main() {
// const WARMUP_COUNT = 5;
const WARMUP_COUNT = 5;
for (let i = 0; i < WARMUP_COUNT; i++) {
await warmupRun(i);
}

await afterFrameAsync();

timedRun();
await timedRun();
}

initializeTemplate().then(main);
Expand Down

0 comments on commit 4b5e755

Please sign in to comment.