-
Notifications
You must be signed in to change notification settings - Fork 10
/
example.js
29 lines (22 loc) · 874 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const puppeteer = require('puppeteer');
const { getPerformanceModel } = require('../index');
init();
async function init() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(
'https://footguns.yonatan.dev/animation/js/?bmt=true&interval=300',
);
await page.tracing.start({ path: 'trace.json' });
await page.waitFor(3000);
const traceBuffer = await page.tracing.stop();
const trace = JSON.parse(traceBuffer.toString());
const performanceModel = await getPerformanceModel(trace);
const frames = performanceModel.frames();
console.log(`FPS: ${1000 / average(frames.map(x => x.duration))}`);
console.log(`Slowest frame: ${Math.max(...frames.map(x => x.duration))} ms`);
await browser.close();
}
function average(values) {
return values.reduce((acc, item) => acc + item, 0) / values.length;
}