Skip to content

Commit

Permalink
feat: vega plots support is removed
Browse files Browse the repository at this point in the history
It wasn't frequently used, so we remove it now to have
less dependencies.

BREAKING CHANGE: ^^^
  • Loading branch information
kirillgroshkov committed Mar 6, 2024
1 parent 5e7c513 commit 76937cf
Show file tree
Hide file tree
Showing 14 changed files with 865 additions and 1,455 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- { uses: actions/setup-node@v4, with: { node-version: 'lts/*', cache: 'yarn' } }

# Cache for npm/npx in ~/.npm
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ~/.npm
key: npm-v1-${{ runner.os }}
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{
"name": "@naturalcycles/bench-lib",
"scripts": {
"prepare": "husky install"
"prepare": "husky"
},
"dependencies": {
"@naturalcycles/js-lib": "^14.0.0",
"@naturalcycles/nodejs-lib": "^13.0.2",
"autocannon": "^7.0.0",
"benchmark": "^2.1.4",
"express": "^4.17.1",
"helmet": "^7.0.0",
"vega": "^5.10.1",
"vega-lite": "^5.0.0"
"helmet": "^7.0.0"
},
"devDependencies": {
"@naturalcycles/dev-lib": "^13.6.0",
Expand Down
2 changes: 1 addition & 1 deletion scripts/bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ runScript(async () => {
},
},
runs: 2,
writePlot: true,
// writePlot: true,
writeSummary: true,
})

Expand Down
2 changes: 1 addition & 1 deletion scripts/demoBench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ runBenchScript({
},
runs: 1,
reportDirPath: './demo',
writePlot: true,
// writePlot: true,
writeSummary: true,
})
4 changes: 2 additions & 2 deletions scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"baseUrl": "./",
"outDir": "../dist",
"lib": ["es2019", "dom"],
"skipLibCheck": true
"skipLibCheck": true,
},
"exclude": ["**/__exclude"]
"exclude": ["**/__exclude"],
}
2 changes: 1 addition & 1 deletion src/bench.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface RunBenchOptions {
*
* @default true
*/
writePlot?: boolean
// writePlot?: boolean // feature disabled

/**
* Plot ascii chart in the terminal:)
Expand Down
4 changes: 2 additions & 2 deletions src/bench.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test('runBench', async () => {
},
runs: 1,
reportDirPath,
writePlot: true,
// writePlot: true,
writeSummary: true,
})

Expand All @@ -30,5 +30,5 @@ test('runBench', async () => {
immediate: expect.any(Number),
})

expect(fs2.pathExists(`${reportDirPath}/runBench.svg`)).toBe(true)
// expect(fs2.pathExists(`${reportDirPath}/runBench.svg`)).toBe(true)
}, 240000)
37 changes: 15 additions & 22 deletions src/bench.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { pDefer, _range } from '@naturalcycles/js-lib'
import { dimGrey, yellow, runScript, fs2 } from '@naturalcycles/nodejs-lib'
import type { Event, Suite } from 'benchmark'
import Benchmark from 'benchmark'
import vega from 'vega'
import type { Spec } from 'vega'
import vegaLite from 'vega-lite'
import type { TopLevelSpec } from 'vega-lite'
import { plotAsciiChart } from './asciiChart.util'
import type { HertzMap, RunBenchOptions } from './bench.model'

Expand All @@ -25,13 +21,7 @@ export function runBenchScript(opt: RunBenchOptions): void {
* Only DeferredFunctions are allowed, because of: https://github.com/bestiejs/benchmark.js/issues/111
*/
export async function runBench(opt: RunBenchOptions): Promise<HertzMap> {
const {
runs = 1,
writeSummary = true,
writePlot = true,
asciiPlot = true,
name = 'runBench',
} = opt
const { runs = 1, writeSummary = true, asciiPlot = true, name = 'runBench' } = opt
const { reportDirPath = `./tmp/${name}` } = opt

console.log(`running benchmark...\n\n`)
Expand Down Expand Up @@ -64,17 +54,18 @@ export async function runBench(opt: RunBenchOptions): Promise<HertzMap> {
console.log(`saved ${dimGrey(summaryJsonPath)}`)
}

if (writePlot) {
fs2.ensureDir(reportDirPath)

const spec = benchResultsToVegaSpec(avg)
const view = new vega.View(vega.parse(spec), { renderer: 'none' })
const svg = await view.toSVG()

const plotPath = `${reportDirPath}/${name}.svg`
fs2.writeFile(plotPath, svg)
console.log(`saved ${dimGrey(plotPath)}`)
}
// Vega plots are currently disabled
// if (writePlot) {
// fs2.ensureDir(reportDirPath)
//
// const spec = benchResultsToVegaSpec(avg)
// const view = new vega.View(vega.parse(spec), { renderer: 'none' })
// const svg = await view.toSVG()
//
// const plotPath = `${reportDirPath}/${name}.svg`
// fs2.writeFile(plotPath, svg)
// console.log(`saved ${dimGrey(plotPath)}`)
// }

if (asciiPlot) {
console.log('\n' + plotAsciiChart(avg))
Expand Down Expand Up @@ -123,6 +114,7 @@ async function runBenchOnce(opt: RunBenchOptions, run: number): Promise<HertzMap
return await defer
}

/*
function benchResultsToVegaSpec(map: HertzMap): Spec {
const values = Object.entries(map).map(([name, hz]) => {
return {
Expand Down Expand Up @@ -161,3 +153,4 @@ function benchResultsToVegaSpec(map: HertzMap): Spec {
const { spec } = vegaLite.compile(liteSpec)
return spec
}
*/
2 changes: 1 addition & 1 deletion src/cannon.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export interface RunCannonOptions {
*
* @default true
*/
writePlots?: boolean
// writePlots?: boolean // feature disabled

/**
* Will write to ${reportDirPath}/${name}.${rawSummary}.json
Expand Down
4 changes: 2 additions & 2 deletions src/cannon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('runCannon', async () => {
cooldown: 0,
reportDirPath,
silent: true,
writePlots: true,
// writePlots: true,
writeSummary: true,
},
)
Expand All @@ -40,5 +40,5 @@ test('runCannon', async () => {
name: 'async',
})

expect(fs2.pathExists(`${reportDirPath}/Benchmark.latencyAvg.svg`)).toBe(true)
// expect(fs2.pathExists(`${reportDirPath}/Benchmark.latencyAvg.svg`)).toBe(true)
}, 240000)
16 changes: 7 additions & 9 deletions src/cannon.util.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type { AddressInfo } from 'node:net'
import { pDefer, pDelay, pMap, StringMap, _omit, _range } from '@naturalcycles/js-lib'
import { pDefer, pDelay, StringMap, _omit, _range } from '@naturalcycles/js-lib'
import { runScript, boldRed, dimGrey, yellow, fs2 } from '@naturalcycles/nodejs-lib'
import vega from 'vega'
import type { Spec } from 'vega'
import vegaLite from 'vega-lite'
import type { TopLevelSpec } from 'vega-lite'
import type {
AutocannonResult,
AutocannonSummary,
Expand Down Expand Up @@ -36,7 +32,6 @@ export async function runCannon(
const opt: RunCannonNormalizedOptions = {
name: 'Benchmark',
reportDirPath: `./tmp/${optInput.name || 'Benchmark'}`,
writePlots: true,
writeSummary: true,
writeRawSummary: true,
runs: 2,
Expand Down Expand Up @@ -92,9 +87,9 @@ export async function runCannon(
fs2.writeJson(`${reportDirPath}/${opt.name}.rawSummary.json`, resultByProfile, { spaces: 2 })
}

if (opt.writePlots) {
await writePlotFiles(opt, summaries)
}
// if (opt.writePlots) {
// await writePlotFiles(opt, summaries)
// }

return summaries
}
Expand Down Expand Up @@ -181,6 +176,7 @@ function toSummary(name: string, result: AutocannonResult): AutocannonSummary {
}
}

/*
async function writePlotFiles(
opt: RunCannonNormalizedOptions,
summaries: AutocannonSummary[],
Expand Down Expand Up @@ -250,6 +246,7 @@ function autocannonSummaryToVegaSpecs(
return specs
}
function mdContent(opt: RunCannonNormalizedOptions, specNames: string[]): string {
return [
`# ${opt.name}`,
Expand All @@ -260,3 +257,4 @@ function mdContent(opt: RunCannonNormalizedOptions, specNames: string[]): string
.filter(Boolean)
.join('\n\n')
}
*/
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"compilerOptions": {
"outDir": "dist",
"lib": ["esnext", "dom"],
"skipLibCheck": true
},
"include": ["src"],
"exclude": ["**/__exclude"]
"exclude": ["**/__exclude"],
}
4 changes: 2 additions & 2 deletions tsconfig.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"skipLibCheck": true,
"declaration": true,
"sourceMap": false
"sourceMap": false,
},
"exclude": ["**/__exclude", "src/test", "src/**/*.test.*"]
"exclude": ["**/__exclude", "src/test", "src/**/*.test.*"],
}
Loading

0 comments on commit 76937cf

Please sign in to comment.