Created
May 6, 2018 00:30
-
-
Save sei0o/083667394341c837bddb1fe3adf682ae to your computer and use it in GitHub Desktop.
Kokkai Speed Battle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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