blob: 602e152756e4f6ee363c4ece4e4e84cf11c397ec [file] [log] [blame]
Alexei Filippovff3b5142018-05-24 03:13:55 +09001// 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.:
Alexei Filippov80d11ff2018-07-04 11:08:38 +09007// $ CHROME_PATH=~/chromium/src/out/Release/chrome node benchmark-octane.js
Alexei Filippovff3b5142018-05-24 03:13:55 +09008
9const puppeteer = require('puppeteer');
10
Alexei Filippovff3b5142018-05-24 03:13:55 +090011async function runOctane(samplingRate) {
12 const args = ['--enable-devtools-experiments'];
13 if (samplingRate)
14 args.push(`--sampling-heap-profiler=${samplingRate}`);
Alexei Filippov80d11ff2018-07-04 11:08:38 +090015 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');
Alexei Filippovff3b5142018-05-24 03:13:55 +090024
Alexei Filippov80d11ff2018-07-04 11:08:38 +090025 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();
Alexei Filippovff3b5142018-05-24 03:13:55 +090035 }
Alexei Filippovff3b5142018-05-24 03:13:55 +090036 }
37}
38
Alexei Filippov80d11ff2018-07-04 11:08:38 +090039async function makeRuns(rates) {
40 const scores = [];
41 for (const rate of rates)
42 scores.push(await runOctane(rate));
43 console.log(scores.join('\t'));
Alexei Filippovff3b5142018-05-24 03:13:55 +090044}
45
46async function main() {
47 console.log(`Using ${process.env.CHROME_PATH || puppeteer.executablePath()}`);
Alexei Filippov80d11ff2018-07-04 11:08:38 +090048 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);
Alexei Filippovff3b5142018-05-24 03:13:55 +090056}
57
58main();