Skip to main content

How to Manage CPU Performance

Overview

warning

This recipe only works when using Chrome DevTools Protocol (CDP).

Read details in the section “How to Use CDP in Testplane

The CPU speed on mobile devices is significantly slower than on computers. Therefore, to emulate CPU speed in puppeteer, there is a method called emulateCPUThrottling.

Example: Slowing Down CPU Speed by 8x

Let's use this method to slow down CPU speed by 8 times:

it("should open yandex.ru with emulation 8x slower CPU", async function () {
// Get puppeteer instance
const puppeteer = await this.browser.getPuppeteer();

// Get the first open page (considering it to be currently active)
const [page] = await puppeteer.pages();

// Slow down the CPU speed by 8 times
await page.emulateCPUThrottling(8);

await this.browser.url("https://yandex.ru");
});

A Small Story About a Workaround

Initially, webdriverio did not support the page.emulateCPUThrottling method because webdriverio used puppeteer-core@9.1.0, not puppeteer-core@10.1.0, which supports this method.

However, this limitation could be bypassed using puppeteer's CDPSession.send() method by sending the browser the Emulation.setCPUThrottlingRate command via CDP:

it("should open yandex.ru with emulation 8x slower CPU", async function () {
// Get puppeteer instance
const puppeteer = await this.browser.getPuppeteer();

// Get the first open page (considering it to be currently active)
const [page] = await puppeteer.pages();

// Create a CDP session
const client = await page.target().createCDPSession();

// Slow down the CPU speed by 8 times
await client.send("Emulation.setCPUThrottlingRate", { rate: 8 });

await this.browser.url("https://yandex.ru");
});

Later, we submitted a requisite pull request to webdriverio to update the version of puppeteer-core. Now, the emulateCPUThrottling method is available in Testplane right out of the box.