• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/src/out/Release/chrome node benchmark-octane.js
8
9const puppeteer = require('puppeteer');
10
11async function runOctane(samplingRate) {
12  const args = ['--enable-devtools-experiments'];
13  if (samplingRate)
14    args.push(`--sampling-heap-profiler=${samplingRate}`);
15  while (true) {
16    let brower;
17    try {
18      browser = await puppeteer.launch({
19          executablePath: process.env.CHROME_PATH, args, headless: true});
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        continue;
31      return parseInt(match[1]);
32    } finally {
33      if (browser)
34        await browser.close();
35    }
36  }
37}
38
39async function makeRuns(rates) {
40  const scores = [];
41  for (const rate of rates)
42    scores.push(await runOctane(rate));
43  console.log(scores.join('\t'));
44}
45
46async function main() {
47  console.log(`Using ${process.env.CHROME_PATH || puppeteer.executablePath()}`);
48  const rates = [0];
49  for (let rate = 8; rate <= 2048; rate *= 2)
50    rates.push(rate);
51  console.log('Rates [KB]:');
52  console.log(rates.join('\t'));
53  console.log('='.repeat(rates.length * 8));
54  for (let i = 0; i < 100; ++i)
55    await makeRuns(rates);
56}
57
58main();
59