benchmark-octane.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. // To benchmark a specific version of Chrome set the CHROME_PATH environment
  5. // variable, e.g.:
  6. // $ CHROME_PATH=~/chromium/src/out/Release/chrome node benchmark-octane.js
  7. const puppeteer = require('puppeteer');
  8. async function runOctane(samplingRate) {
  9. const args = ['--enable-devtools-experiments'];
  10. if (samplingRate)
  11. args.push(`--memlog=all`, `--memlog-sampling-rate=${samplingRate}`);
  12. while (true) {
  13. let browser;
  14. try {
  15. browser = await puppeteer.launch({
  16. executablePath: process.env.CHROME_PATH, args, headless: true});
  17. const page = await browser.newPage();
  18. await page.goto('https://chromium.github.io/octane/');
  19. await page.waitForSelector('#run-octane'); // Just in case.
  20. await page.click('#run-octane');
  21. const scoreDiv = await page.waitForSelector('#main-banner:only-child',
  22. {timeout: 120000});
  23. const scoreText = await page.evaluate(e => e.innerText, scoreDiv);
  24. const match = /Score:\s*(\d+)/.exec(scoreText);
  25. if (match.length < 2)
  26. continue;
  27. return parseInt(match[1]);
  28. } finally {
  29. if (browser)
  30. await browser.close();
  31. }
  32. }
  33. }
  34. async function makeRuns(rates) {
  35. const scores = [];
  36. for (const rate of rates)
  37. scores.push(await runOctane(rate));
  38. console.log(scores.join('\t'));
  39. }
  40. async function main() {
  41. console.log(`Using ${process.env.CHROME_PATH || puppeteer.executablePath()}`);
  42. const rates = [0];
  43. for (let rate = 8; rate <= 2048; rate *= 2)
  44. rates.push(rate);
  45. console.log('Rates [KB]:');
  46. console.log(rates.join('\t'));
  47. console.log('='.repeat(rates.length * 8));
  48. for (let i = 0; i < 100; ++i)
  49. await makeRuns(rates);
  50. }
  51. main();