Puppeteer (Google) and Playwright-Chromium (Microsoft) are libraries used to programmatically control browsers. This article compares the libraries across six (6) criteria.
Winner: Puppeteer ✅
Puppeteer is faster at launching an uncached browser with the same configurations. For each library, a browser and a new page are started with the scripts shown below. Both launches also include HAR recording, viewport setup, and adds custom headers to the page.
const browser = playwright.chromium.launchPersistentContext(
tmpDir, {...options}
);
const page = await browser.newPage();
const browser = puppeteerLib.launch({
...options,
userDataDir: tmpDir
});
const page = await browser.newPage();
Winner: Puppeteer ✅
Flows visit a page, click on elements, and wait for data to be loaded. Flows are multi-step. The flows used in this test are defined in the Test Setup section. Puppeteer performs in both the long and short script scenarios.
NOTE: High startup costs lead to the short script performing worse than the long script.
*Winner: Puppeteer ✅ *
Both the libraries were fairly similar in terms of performance during the long script to shutdown the script. This is likely due to less contention on the resources. However, in the shorter scripts where contention could be higher, Playwright underperformed Puppeteer.
await page.close();
await browser.close();
Winner: Puppeteer ✅
Puppeteer does all of it just faster. Here are the stats. Please scroll up for the definitions of short and long scripts.
Process Memory
Winner: Puppeteer ✅
Puppeteer uses less memory than Playwright across the tests when measured with the following code.
process.memoryUsage().rss
This means that the NodeJS process memory is smaller. The absolute memory is tabled below in megabytes (MB).
Winner: Puppeteer ✅
Running each phase of the test: startup, flow, and shutdown as many times as possible for 5 minutes gives us the throughput/minute. Puppeteer can get the highest throughput.
To maximize the throughput (for short scripts), set the browsers per core between 3 and 5. So, an eight (8) core machine can between 24 and 40 Chrome browsers.
NOTE: These metrics are dependent on the duration of the flow. Longer flows will likely offer higher iterations/min better with higher browsers/core.
Puppeteer performs better than Playwright in these test scenarios. The analysis show at least a 25% performance improvement with Puppeteer. At BrowserStorm, we recommend Puppeteer since it offers a higher throughput with Chromium browsers without much performance optimizations. As a result, load testing your system will be more cost-efficient.
This is not to say Playwright doesn't have its advantages e.g. ShadowDOM and WebComponents.
Sample Test Results - https://www.browserstorm.com/test/XkM2VW63befilDl
Thank you for reading!
Источник: dev.to
Наш сайт является информационным посредником. Сообщить о нарушении авторских прав.
performance webdev javascript cloud