Skip to content

Commit

Permalink
fix: store now works peroply with new types
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Silberman committed Jun 20, 2019
1 parent cf40e33 commit 718170f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 42 deletions.
70 changes: 34 additions & 36 deletions packages/@best/api-db/src/store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import crypto from 'crypto';
import { loadDbFromConfig } from './utils';
import { TemporarySnapshot, Metric } from './types';
import { FrozenGlobalConfig, BenchmarkResultsSnapshot, StatsNode, RunnerConfig } from '@best/types';
import { FrozenGlobalConfig, BenchmarkResultsSnapshot, BenchmarkMetricNames, StatsNode } from '@best/types';

interface RunSettings {
similarityHash: string;
Expand All @@ -19,19 +19,39 @@ function md5(data: string) {
.digest('hex');
}

const generateSnapshots = (runSettings: RunSettings, benchmarks: StatsNode[], snapshots: TemporarySnapshot[] = []): TemporarySnapshot[] => {
const things: TemporarySnapshot[] = benchmarks.reduce((results, benchmark): TemporarySnapshot[] => {
const generateSnapshots = (runSettings: RunSettings, benchmarks: StatsNode[], groupName?: string): TemporarySnapshot[] => {
return benchmarks.reduce((results, benchmark): TemporarySnapshot[] => {
if (benchmark.type === "benchmark") {
Object.keys(benchmark.metrics).forEach((key: string) => {
const values = benchmark.metrics[key as BenchmarkMetricNames].stats;
const metrics = Object.keys(benchmark.metrics).reduce((results, metricName: string): Metric[] => {
const values = benchmark.metrics[metricName as BenchmarkMetricNames];

if (values) {
return [
...results,
{
name: metricName,
duration: values.stats.median,
stdDeviation: values.stats.medianAbsoluteDeviation
}
]
}

return results;
}, <Metric[]>[])

const snapshot: TemporarySnapshot = {
...runSettings,
name: `${groupName ? groupName + '/' : ''}${benchmark.name}`,
metrics: metrics
}

})
return [...results, snapshot]
} else if (benchmark.type === "group") {
return [...results, ...generateSnapshots(runSettings, benchmark.nodes, benchmark.name)]
}

return results;
}, <TemporarySnapshot[]>[])

return snapshots;
}

export const saveBenchmarkSummaryInDB = (benchmarkResults: BenchmarkResultsSnapshot[], globalConfig: FrozenGlobalConfig) => {
Expand Down Expand Up @@ -61,34 +81,12 @@ export const saveBenchmarkSummaryInDB = (benchmarkResults: BenchmarkResultsSnaps
branch
}

const snapshotsToSave: TemporarySnapshot[] = [];

if (! stats) { return };

stats.results.map((node) => {

})

stats.benchmarks.forEach((element: any) => {
element.benchmarks.forEach((bench: any) => {
const metricKeys = Object.keys(bench).filter(key => key !== 'name')
const metrics = metricKeys.map(name => ({
name,
duration: bench[name].median,
stdDeviation: bench[name].medianAbsoluteDeviation,
}))

const snapshot = {
...runSettings,
name: `${element.name}/${bench.name}`,
metrics: metrics
}
snapshotsToSave.push(snapshot);

});
});

return db.saveSnapshots(snapshotsToSave, projectName);
if (stats) {
const snapshots = generateSnapshots(runSettings, stats.results);
return db.saveSnapshots(snapshots, projectName);
} else {
return false;
}
}),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function fib(n) {
return n <= 1 ? 1 : fib(n - 1) + fib(n - 2);
}

describe('js-execution2', () => {
describe('js-execution3', () => {
benchmark('fibonacci', () => {
run(() => {
return fib(15);
Expand Down
6 changes: 1 addition & 5 deletions packages/best-benchmarks/best.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
module.exports = {
projectName: 'best-benchmark',
apiDatabase: {
adapter: 'sql/postgres',
path: `postgresql://localhost`
}
projectName: 'best-benchmark'
};

0 comments on commit 718170f

Please sign in to comment.