throttleCPU(cpuProfile)
根据 cpuProfile
中指定的 rate
,限制 Chrome/Chromium 中的 CPU 以降低其速度。
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
cpuProfile | CPUProfile | null | 这是一个必需参数。 |
cpuProfile.rate | number | 1 | rate 作为减速因子(1 表示不限制,2 表示减速 2 倍,依此类推)。 |
返回值
类型 | 描述 |
---|---|
Promise<void> | 当 CPU 已被限制到指定速率时,此 Promise 将会完成。 |
示例
import { browser } from 'k6/browser';
export const options = {
scenarios: {
browser: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
};
export default async function () {
const context = await browser.newContext();
const page = await context.newPage();
try {
await page.throttleCPU({ rate: 4 });
await page.goto('https://test.k6.io/', { waitUntil: 'networkidle' });
} finally {
await page.close();
}
}