From c8a6638d4ebdb46dae42e165ae064cf43a50ef5f Mon Sep 17 00:00:00 2001 From: Emma Imber Date: Thu, 6 Jun 2024 12:07:39 +0100 Subject: [PATCH 1/6] Add more test articles and run through 3 times --- .../benchmark/test-ad-load-time.spec.ts | 64 ++++++++++--------- playwright/fixtures/pages/load-time-pages.ts | 60 +++++++++++++++++ 2 files changed, 93 insertions(+), 31 deletions(-) diff --git a/playwright/benchmark/test-ad-load-time.spec.ts b/playwright/benchmark/test-ad-load-time.spec.ts index 482464fc1..2bdc51ca9 100644 --- a/playwright/benchmark/test-ad-load-time.spec.ts +++ b/playwright/benchmark/test-ad-load-time.spec.ts @@ -41,47 +41,49 @@ const interceptCommercial = (page: Page) => test.describe.configure({ mode: 'parallel' }); test.describe('Test how long top-above-nav takes to load', () => { - for (const article of loadTimePages) { - test(`${article.path}`, async ({ page }, testInfo) => { - await interceptCommercial(page); + for (let i = 0; i < 3; i++) { + for (const article of loadTimePages) { + test(`${article.path}`, async ({ page }, testInfo) => { + await interceptCommercial(page); - const client = await page.context().newCDPSession(page); + const client = await page.context().newCDPSession(page); - await client.send( - 'Network.emulateNetworkConditions', - networkConditions, - ); - - await page.setViewportSize(viewport); + await client.send( + 'Network.emulateNetworkConditions', + networkConditions, + ); - await loadPage(page, article.path); + await page.setViewportSize(viewport); - const startRenderingTime = Date.now(); + await loadPage(page, article.path); - await waitForSlot(page, 'top-above-nav'); + const startRenderingTime = Date.now(); - const renderingTime = Date.now() - startRenderingTime; + await waitForSlot(page, 'top-above-nav'); - console.log(`Ad rendered in ${renderingTime} ms`); + const renderingTime = Date.now() - startRenderingTime; - const file = resolve( - __dirname, - `../../benchmark-results/${testInfo.project.name}/ad-rendering-time-${testInfo.workerIndex}.txt`, - ); + console.log(`Ad rendered in ${renderingTime} ms`); - if (!existsSync(file)) { - mkdirSync( - resolve( - __dirname, - `../../benchmark-results/${testInfo.project.name}`, - ), - { - recursive: true, - }, + const file = resolve( + __dirname, + `../../benchmark-results/${testInfo.project.name}/ad-rendering-time-${testInfo.workerIndex}.txt`, ); - } - await appendFile(file, String(renderingTime) + '\n'); - }); + if (!existsSync(file)) { + mkdirSync( + resolve( + __dirname, + `../../benchmark-results/${testInfo.project.name}`, + ), + { + recursive: true, + }, + ); + } + + await appendFile(file, String(renderingTime) + '\n'); + }); + } } }); diff --git a/playwright/fixtures/pages/load-time-pages.ts b/playwright/fixtures/pages/load-time-pages.ts index ef5866292..f97daa560 100644 --- a/playwright/fixtures/pages/load-time-pages.ts +++ b/playwright/fixtures/pages/load-time-pages.ts @@ -124,6 +124,66 @@ const loadTimePages: GuPage[] = [ path: '/technology/2024/apr/30/amazon-sales-report-ai', }), }, + { + path: getTestUrl({ + stage, + path: '/film/article/2024/jun/06/show-me-the-money-how-unofficial-merch-is-cashing-in-on-movie-quotes', + }), + }, + { + path: getTestUrl({ + stage, + path: '/sport/article/2024/jun/05/family-mum-of-three-helen-glover-2024-olympics-paris-rowing-team-gb', + }), + }, + { + path: getTestUrl({ + stage, + path: '/travel/article/2024/may/26/how-to-keep-your-cool-cycling-up-italian-mountains-with-a-teenager-in-tow', + }), + }, + { + path: getTestUrl({ + stage, + path: '/environment/article/2024/may/23/fishing-barbara-creecy-minister-court-south-african-penguins-facing-extinction', + }), + }, + { + path: getTestUrl({ + stage, + path: '/travel/article/2024/jun/05/sailing-voyage-the-wash-norfolk-potatoes-chip-shop-kings-lynn', + }), + }, + { + path: getTestUrl({ + stage, + path: '/food/2024/apr/09/swapping-red-meat-for-herring-sardines-and-anchovies-could-save-75000-lives-study-suggests', + }), + }, + { + path: getTestUrl({ + stage, + path: '/science/article/2024/jun/05/carbon-detected-in-galaxy-observed-350m-years-after-big-bang', + }), + }, + { + path: getTestUrl({ + stage, + path: '/commentisfree/article/2024/jun/06/undecided-voters-british-politics-vote-election', + }), + }, + { + path: getTestUrl({ + stage, + path: '/lifeandstyle/article/2024/may/31/t26-surprisingly-useful-gadgets-you-didnt-know-you-needed', + }), + }, + { + path: getTestUrl({ + stage, + path: '/books/ng-interactive/2024/jun/05/this-months-best-paperbacks-zadie-smith-matthew-perry-and-more', + }), + }, ]; export { loadTimePages }; From 3e89e5d0b260de7ed3ac621784da181ccd729b6b Mon Sep 17 00:00:00 2001 From: Emma Imber Date: Thu, 6 Jun 2024 12:11:09 +0100 Subject: [PATCH 2/6] Update test name --- playwright/benchmark/test-ad-load-time.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playwright/benchmark/test-ad-load-time.spec.ts b/playwright/benchmark/test-ad-load-time.spec.ts index 2bdc51ca9..3491f05e5 100644 --- a/playwright/benchmark/test-ad-load-time.spec.ts +++ b/playwright/benchmark/test-ad-load-time.spec.ts @@ -43,7 +43,7 @@ test.describe.configure({ mode: 'parallel' }); test.describe('Test how long top-above-nav takes to load', () => { for (let i = 0; i < 3; i++) { for (const article of loadTimePages) { - test(`${article.path}`, async ({ page }, testInfo) => { + test(`${article.path} run ${i}`, async ({ page }, testInfo) => { await interceptCommercial(page); const client = await page.context().newCDPSession(page); From b282092817570193f6730072704988e8d266c091 Mon Sep 17 00:00:00 2001 From: Emma Imber Date: Thu, 6 Jun 2024 12:18:35 +0100 Subject: [PATCH 3/6] Only run file once --- .../benchmark/test-ad-load-time.spec.ts | 64 +++++++++---------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/playwright/benchmark/test-ad-load-time.spec.ts b/playwright/benchmark/test-ad-load-time.spec.ts index 3491f05e5..482464fc1 100644 --- a/playwright/benchmark/test-ad-load-time.spec.ts +++ b/playwright/benchmark/test-ad-load-time.spec.ts @@ -41,49 +41,47 @@ const interceptCommercial = (page: Page) => test.describe.configure({ mode: 'parallel' }); test.describe('Test how long top-above-nav takes to load', () => { - for (let i = 0; i < 3; i++) { - for (const article of loadTimePages) { - test(`${article.path} run ${i}`, async ({ page }, testInfo) => { - await interceptCommercial(page); + for (const article of loadTimePages) { + test(`${article.path}`, async ({ page }, testInfo) => { + await interceptCommercial(page); - const client = await page.context().newCDPSession(page); + const client = await page.context().newCDPSession(page); - await client.send( - 'Network.emulateNetworkConditions', - networkConditions, - ); + await client.send( + 'Network.emulateNetworkConditions', + networkConditions, + ); + + await page.setViewportSize(viewport); - await page.setViewportSize(viewport); + await loadPage(page, article.path); - await loadPage(page, article.path); + const startRenderingTime = Date.now(); - const startRenderingTime = Date.now(); + await waitForSlot(page, 'top-above-nav'); - await waitForSlot(page, 'top-above-nav'); + const renderingTime = Date.now() - startRenderingTime; - const renderingTime = Date.now() - startRenderingTime; + console.log(`Ad rendered in ${renderingTime} ms`); - console.log(`Ad rendered in ${renderingTime} ms`); + const file = resolve( + __dirname, + `../../benchmark-results/${testInfo.project.name}/ad-rendering-time-${testInfo.workerIndex}.txt`, + ); - const file = resolve( - __dirname, - `../../benchmark-results/${testInfo.project.name}/ad-rendering-time-${testInfo.workerIndex}.txt`, + if (!existsSync(file)) { + mkdirSync( + resolve( + __dirname, + `../../benchmark-results/${testInfo.project.name}`, + ), + { + recursive: true, + }, ); + } - if (!existsSync(file)) { - mkdirSync( - resolve( - __dirname, - `../../benchmark-results/${testInfo.project.name}`, - ), - { - recursive: true, - }, - ); - } - - await appendFile(file, String(renderingTime) + '\n'); - }); - } + await appendFile(file, String(renderingTime) + '\n'); + }); } }); From 2fd728df447b87127e4a5f1939300135a6e8dda9 Mon Sep 17 00:00:00 2001 From: Emma Imber Date: Thu, 6 Jun 2024 12:22:36 +0100 Subject: [PATCH 4/6] Switch out article --- playwright/fixtures/pages/load-time-pages.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playwright/fixtures/pages/load-time-pages.ts b/playwright/fixtures/pages/load-time-pages.ts index f97daa560..122705d70 100644 --- a/playwright/fixtures/pages/load-time-pages.ts +++ b/playwright/fixtures/pages/load-time-pages.ts @@ -151,7 +151,7 @@ const loadTimePages: GuPage[] = [ { path: getTestUrl({ stage, - path: '/travel/article/2024/jun/05/sailing-voyage-the-wash-norfolk-potatoes-chip-shop-kings-lynn', + path: '/travel/article/2024/may/29/an-alternative-guide-to-the-lake-district-cumbria', }), }, { From 6d7b77c24244ce7db12d7781bfe3214c8c95b5bb Mon Sep 17 00:00:00 2001 From: Emma Imber Date: Thu, 6 Jun 2024 14:10:39 +0100 Subject: [PATCH 5/6] Replace article --- playwright/fixtures/pages/load-time-pages.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playwright/fixtures/pages/load-time-pages.ts b/playwright/fixtures/pages/load-time-pages.ts index 122705d70..d184827c6 100644 --- a/playwright/fixtures/pages/load-time-pages.ts +++ b/playwright/fixtures/pages/load-time-pages.ts @@ -145,7 +145,7 @@ const loadTimePages: GuPage[] = [ { path: getTestUrl({ stage, - path: '/environment/article/2024/may/23/fishing-barbara-creecy-minister-court-south-african-penguins-facing-extinction', + path: '/environment/article/2024/jun/04/country-diary-these-summer-migrants-are-remarkable-and-humbling', }), }, { From 927350a59d8a4096d4192d7174fb2dbdde170a00 Mon Sep 17 00:00:00 2001 From: Emma Imber Date: Thu, 6 Jun 2024 14:53:22 +0100 Subject: [PATCH 6/6] Round average load time to avoid recurring decimals --- playwright/benchmark/average.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playwright/benchmark/average.spec.ts b/playwright/benchmark/average.spec.ts index a0823ad31..b1e4a418a 100644 --- a/playwright/benchmark/average.spec.ts +++ b/playwright/benchmark/average.spec.ts @@ -22,7 +22,7 @@ test('average', ({ page }, testInfo) => { const testSum = lines.reduce((acc, line) => acc + parseInt(line), 0); // average of all the lines in all the files - const average = testSum / lines.length; + const average = Math.round(testSum / lines.length); writeFileSync(resolve(path, `average.txt`), String(average));