Alexei Filippov | ff3b514 | 2018-05-24 03:13:55 +0900 | [diff] [blame^] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // To benchmark a specific version of Chrome set the CHROME_PATH environment |
| 6 | // variable, e.g.: |
| 7 | // $ CHROME_PATH=~/chromium/out/Release/chrome node benchmark-octane.js |
| 8 | |
| 9 | const puppeteer = require('puppeteer'); |
| 10 | |
| 11 | let base_score; |
| 12 | |
| 13 | async function runOctane(samplingRate) { |
| 14 | const args = ['--enable-devtools-experiments']; |
| 15 | if (samplingRate) |
| 16 | args.push(`--sampling-heap-profiler=${samplingRate}`); |
| 17 | const browser = await puppeteer.launch({ |
| 18 | executablePath: process.env.CHROME_PATH, args, headless: true}); |
| 19 | try { |
| 20 | const page = await browser.newPage(); |
| 21 | await page.goto('https://chromium.github.io/octane/'); |
| 22 | await page.waitForSelector('#run-octane'); // Just in case. |
| 23 | await page.click('#run-octane'); |
| 24 | |
| 25 | const scoreDiv = await page.waitForSelector('#main-banner:only-child', |
| 26 | {timeout: 120000}); |
| 27 | const scoreText = await page.evaluate(e => e.innerText, scoreDiv); |
| 28 | const match = /Score:\s*(\d+)/.exec(scoreText); |
| 29 | if (match.length < 2) { |
| 30 | console.log(`Error: cannot parse score from '${scoreText}'`); |
| 31 | return 0; |
| 32 | } |
| 33 | return parseInt(match[1]); |
| 34 | } finally { |
| 35 | await browser.close(); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | async function makeRuns(rate) { |
| 40 | console.log(`tesing rate: ${rate}`); |
| 41 | let sum = 0; |
| 42 | let sum2 = 0; |
| 43 | const n = 10; |
| 44 | for (let i = 0; i < n; ++i) { |
| 45 | const score = await runOctane(rate); |
| 46 | console.log(score); |
| 47 | sum += score; |
| 48 | sum2 += score * score; |
| 49 | } |
| 50 | const mean = sum / n; |
| 51 | const stdev = Math.sqrt(sum2 / n - mean * mean); |
| 52 | console.log(`rate: ${rate} mean: ${mean} stdev: ${stdev}`); |
| 53 | return mean; |
| 54 | } |
| 55 | |
| 56 | async function main() { |
| 57 | console.log(`Using ${process.env.CHROME_PATH || puppeteer.executablePath()}`); |
| 58 | const base_score = await makeRuns(0); |
| 59 | for (let rate = 32; rate <= 2048; rate *= 2) { |
| 60 | const score = await makeRuns(rate); |
| 61 | console.log(`slowdown: ${(100 - score / base_score * 100).toFixed(2)}%\n`); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | main(); |
| 66 | |