Skip to content

Commit

Permalink
✨ NEW: Capture python version
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Aug 17, 2020
1 parent 39561a5 commit 58c21e5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
5 changes: 5 additions & 0 deletions src/assets/funcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ export function renderGraph(canvas, dataset, labels, xAxis, alpha = 60, labelStr
lines.push(` ${key}: ${value}`)
}
}
if (data.extra) {
for (const [key, value] of Object.entries(data.extra)) {
lines.push(`${key}: ${value}`)
}
}
return '\n' + lines.join('\n') + '\n';
},
label: item => {
Expand Down
33 changes: 19 additions & 14 deletions src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface Benchmark {
date: number;
benches: BenchmarkResult[];
cpu?: CpuData;
extra?: { [key: string]: string };
}

export interface PytestBenchmarkJson {
Expand Down Expand Up @@ -145,20 +146,23 @@ function getCommit(): Commit {
/* eslint-enable @typescript-eslint/camelcase */
}

function extractPytestResult(output: string): BenchmarkResult[] {
function extractPytestResult(output: string): { results: BenchmarkResult[]; extra: { [key: string]: string } } {
try {
const json: PytestBenchmarkJson = JSON.parse(output);
return json.benchmarks.map(bench => {
const stats = bench.stats;
const name = bench.fullname;
const group = bench.group;
const value = stats.ops;
const unit = 'iter/sec';
const range = `stddev: ${precise(stats.stddev)}`;
const [mean, meanUnit] = getHumanReadableUnitValue(stats.mean);
const extra = `mean: ${precise(mean)} ${meanUnit}\nrounds: ${stats.rounds}`;
return { name, value, unit, range, group, extra };
});
return {
extra: { pythonVersion: json.machine_info.python_version },
results: json.benchmarks.map(bench => {
const stats = bench.stats;
const name = bench.fullname;
const group = bench.group;
const value = stats.ops;
const unit = 'iter/sec';
const range = `stddev: ${precise(stats.stddev)}`;
const [mean, meanUnit] = getHumanReadableUnitValue(stats.mean);
const extra = `mean: ${precise(mean)} ${meanUnit}\nrounds: ${stats.rounds}`;
return { name, value, unit, range, group, extra };
}),
};
} catch (err) {
throw new Error(
`Output file for 'pytest' must be JSON file generated by --benchmark-json option: ${err.message}`,
Expand All @@ -171,7 +175,7 @@ export async function extractResult(config: Config): Promise<Benchmark> {

const benches = extractPytestResult(output);

if (benches.length === 0) {
if (benches.results.length === 0) {
throw new Error(`No benchmark result was found in ${config.outputFilePath}. Benchmark output was '${output}'`);
}

Expand All @@ -181,8 +185,9 @@ export async function extractResult(config: Config): Promise<Benchmark> {

return {
cpu: { speed, cores, physicalCores, processors },
extra: benches.extra,
commit,
date: Date.now(),
benches,
benches: benches.results,
};
}
6 changes: 5 additions & 1 deletion test/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ describe('check assets', function() {
A.ok(s, 'main script');
});
it('main.js is valid Javascript', async function() {
// Verify HTML syntax
const js = await fs.readFile(join(__dirname, '../src/assets/main.js'), 'utf8');
// Verify JavaScript syntax. It raises an error if invalid
JsParser.parse(js, { sourceType: 'module' });
});
it('funcs.js is valid Javascript', async function() {
const js = await fs.readFile(join(__dirname, '../src/assets/funcs.js'), 'utf8');
// Verify JavaScript syntax. It raises an error if invalid
JsParser.parse(js, { sourceType: 'module' });
});
});

0 comments on commit 58c21e5

Please sign in to comment.