Instantly share code, notes, and snippets.

Embed
What would you like to do?
Kokkai Speed Battle
const puppeteer = require('puppeteer')
const URLs = [
'http://abehiroshi.la.coocan.jp/',
'https://www.jcp.or.jp/',
'https://www.komei.or.jp/',
'https://cdp-japan.jp/',
'https://kibounotou.jp/',
'https://o-ishin.jp/',
'http://www.liberalparty.jp/',
'http://www5.sdp.or.jp/',
'https://www.jimin.jp/',
];
async function measureTime (browser, url) {
let results = []
const page = await browser.newPage()
for (let i = 0; i < 10; i++) {
await page.goto(url, {waitUntil: 'load', timeout: 0})
// await page.goto(url, {waitUntil: 'networkidle0'})
results.push(await page.evaluate(() => {
const tim = window.performance.timing
return tim.loadEventEnd - tim.navigationStart
}))
console.log([i, url, results[results.length - 1]])
}
await page.close()
return results.reduce((prev, cur) => prev + cur) / 10.0 // average
}
(async () => {
const browser = await puppeteer.launch({
args: ['--disable-setuid-sandbox', '--no-sandbox']
})
const results = await Promise.all(URLs.map(url => measureTime(browser, url)))
console.log(results.map((time, i) => [URLs[i], time]).sort((a, b) => a[1] - b[1]))
await browser.close()
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment