Skip to content

Commit

Permalink
Move lines
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Aug 18, 2019
1 parent dd39a60 commit 33a4cdd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 48 deletions.
10 changes: 3 additions & 7 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { getOpts } from './options/main.js'
import { report } from './report/main.js'
import { add } from './store/add.js'
import { get } from './store/get.js'
import { save } from './store/save.js'
import { remove as removeFromStore } from './store/remove.js'
import { runBenchmark } from './run.js'

Expand All @@ -13,13 +12,10 @@ export const run = async function(opts) {

const benchmark = await runBenchmark(optsA)

const [benchmarkA, benchmarks] = await add(benchmark, optsA)
const [{ job }, benchmarks] = await add(benchmark, optsA)

const [benchmarkB] = await Promise.all([
report(benchmarkA.job, benchmarks, { ...optsA, show: false }),
save(benchmarkA, optsA),
])
return benchmarkB
const benchmarkA = await report(job, benchmarks, { ...optsA, show: false })
return benchmarkA
}

// Show a previous benchmark
Expand Down
43 changes: 42 additions & 1 deletion src/store/add.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mergeBenchmarks } from '../jobs/merge.js'
import { addJob } from '../jobs/options.js'
import { omit } from '../utils/main.js'

import { list } from './list.js'

Expand All @@ -8,8 +9,48 @@ export const add = async function(benchmark, opts) {
const benchmarks = await list(opts)

const benchmarkA = addJob(benchmark, benchmarks, opts)
const benchmarksA = [...benchmarks, benchmarkA]
await save(benchmarkA, opts)

const benchmarksA = [...benchmarks, benchmarkA]
const benchmarksB = mergeBenchmarks(benchmarksA)
return [benchmarkA, benchmarksB]
}

// Save benchmark results so they can be compared or shown later
const save = async function(
benchmark,
{ save: saveOpt, store: { add: addToStore, opts } },
) {
if (!saveOpt) {
return
}

const benchmarkA = normalizeBenchmark(benchmark)

try {
await addToStore(benchmarkA, opts)
} catch (error) {
throw new Error(`Could not save benchmark: ${error.message}`)
}
}

// Benchmark information that are too big are not persisted.
// We otherwise try to persist everything, so that `--show` report the same
// information.
// We try to only persist what cannot be computed runtime (which is done by
// `addPrintedInfo()` during reporting). This includes
// `iteration.name|columnName` which are only computed for progress reporters,
// but re-computer after previous benchmarks loading/merging.
const normalizeBenchmark = function({ iterations, ...benchmark }) {
const iterationsA = iterations.map(normalizeIteration)
return { ...benchmark, iterations: iterationsA }
}

const normalizeIteration = function({ stats, ...iteration }) {
const iterationA = omit(iteration, OMITTED_PROPS)
const statsA = omit(stats, OMITTED_STATS_PROPS)
return { ...iterationA, stats: statsA }
}

const OMITTED_PROPS = ['name', 'columnName']
const OMITTED_STATS_PROPS = ['histogram', 'percentiles']
40 changes: 0 additions & 40 deletions src/store/save.js

This file was deleted.

0 comments on commit 33a4cdd

Please sign in to comment.