forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sandbox-performance-benchmark.js
35 lines (30 loc) · 886 Bytes
/
sandbox-performance-benchmark.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
30
31
32
33
34
35
const puppeteer = require('puppeteer');
function pageLoaded(page) {
return new Promise(resolve => {
page.exposeFunction('__puppeteer__', () => {
if (resolve) {
resolve();
}
});
});
}
let browser = puppeteer.launch({ headless: true });
const SANDBOX_ID = process.argv[2];
const results = [];
(async function() {
browser = await browser;
console.log('Testing speed of ' + SANDBOX_ID);
for (let i = 0; i < (process.argv[3] || 10); i++) {
const page = await browser.newPage();
const waitFunction = pageLoaded(page);
page.goto('http:https://localhost:3000/#' + SANDBOX_ID);
const a = Date.now();
await waitFunction;
const d = Date.now() - a;
results.push(d);
console.log('Run #' + i + ': ' + d);
page.close();
}
console.log('Results', results.reduce((p, n) => p + n, 0) / results.length);
process.exit(0);
})();