Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improved benchmark result in github actions #5013

Merged
merged 1 commit into from
Jul 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions test/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { performance, PerformanceObserver } = require('perf_hooks');
const { spawn } = require('child_process');
const { spawn: spawnAsync } = require('hexo-util');
const { rmdir, exists } = require('hexo-fs');
const { appendFileSync: appendFile } = require('fs');
const { join, resolve } = require('path');
const log = require('hexo-log')();
const { red } = require('picocolors');
Expand All @@ -26,6 +27,8 @@ const zeroEksDir = process.env.TRAVIS_BUILD_DIR
: resolve(testDir, '0x');
const hexoBin = resolve(testDir, 'node_modules/.bin/hexo');

const isGitHubActions = process.env.GITHUB_ACTIONS;

const zeroEks = require('0x');

let isProfiling = process.argv.join(' ').includes('--profiling');
Expand All @@ -41,6 +44,12 @@ if (!isProfiling && !isBenchmark) {

if (isBenchmark) {
log.info('Running benchmark');

if (isGitHubActions) {
log.info('Running in GitHub Actions.');
appendFile(process.env.GITHUB_STEP_SUMMARY, '# Benchmark Result\n');
}

await cleanUp();
await run_benchmark('Cold processing');
await run_benchmark('Hot processing');
Expand Down Expand Up @@ -76,8 +85,14 @@ async function run_benchmark(name) {

if (measureFinished) {
obs.disconnect();

if (isGitHubActions) {
appendFile(process.env.GITHUB_STEP_SUMMARY, `\n## ${name}\n\n| Step | Cost time (s) |\n| --- | --- |\n${Object.keys(result).map(name => `| ${name} | ${result[name]['Cost time (s)']} |`).join('\n')}\n`);
}

console.log(name);
console.table(result);

resolve(result);
}
});
Expand Down