Skip to content

Commit

Permalink
Add --tracing to benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
mxstbr committed Jul 5, 2018
1 parent 81df325 commit 904a7f6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ lib
sandbox/node_modules
*.log
test-results.json
mount-deep-tree-trace.json
mount-wide-tree-trace.json
update-dynamic-styles-trace.json
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ lib
sandbox/node_modules
*.log
test-results.json
mount-deep-tree-trace.json
mount-wide-tree-trace.json
update-dynamic-styles-trace.json

benchmarks
12 changes: 10 additions & 2 deletions benchmarks/run-headless.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,34 @@ const path = require('path');
const puppeteer = require('puppeteer');

const tests = ['Mount deep tree', 'Mount wide tree', 'Update dynamic styles'];
const tracing = process.argv.some(arg => arg.indexOf('tracing') > -1);

if (tracing) {
console.log('\nTracing enabled. (note that this might impact benchmark results, we recommend leaving this turned off unless you need a trace)')
}

(async () => {
console.log('\nStarting headless browser...')
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.tracing.start({ path: 'benchmark-trace.json' });
console.log('Opening benchmark app...')
await page.goto(`file://${path.join(__dirname, './dist/index.html')}`);

console.log('Running benchmarks... (this may take a minute; do not use your machine while these are running!)')
console.log('Running benchmarks... (this may take a minute or two; do not use your machine while these are running!)')
for (var i = 0; i < tests.length; i++) {
const test = tests[i];
const traceFile = `${test.toLowerCase().replace(/\s/g, '-')}-trace.json`;
// styled-components is auto-selected, so all we gotta do is select the benchmark and press "Run"
await page.select('[data-testid="benchmark-picker"]', test);
await page.waitForSelector('[data-testid="run-button"]')
if (tracing) await page.tracing.start({ path: traceFile });
await page.click('[data-testid="run-button"]')
await page.waitForSelector(`[data-testid="${test} results"]`)
if (tracing) await page.tracing.stop();
const result = await page.$eval(`[data-testid="${test} results"]`, node => node.innerText)
console.log(`\n---${test}---`)
console.log(result)
console.log('Trace written to', traceFile)
}

console.log('Done!')
Expand Down

0 comments on commit 904a7f6

Please sign in to comment.