Skip to content

Commit

Permalink
fix: deps
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Jan 16, 2024
1 parent 52e56a9 commit 5e7c513
Show file tree
Hide file tree
Showing 6 changed files with 362 additions and 400 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
env: { NODE_OPTIONS: '--max-old-space-size=3200' }
steps:
- { uses: actions/checkout@v4, with: { persist-credentials: true } }
- { uses: actions/setup-node@v4, with: { node-version: 20, cache: 'yarn' } }
- { uses: actions/setup-node@v4, with: { node-version: 'lts/*', cache: 'yarn' } }

# Cache for npm/npx in ~/.npm
- uses: actions/cache@v3
Expand Down
8 changes: 4 additions & 4 deletions src/bench.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { _emptyDirSync, _pathExistsSync, _readJsonSync } from '@naturalcycles/nodejs-lib'
import { fs2 } from '@naturalcycles/nodejs-lib'
import { runBench } from './bench.util'
import { tmpDir } from './test/paths.cnst'

test('runBench', async () => {
const reportDirPath = `${tmpDir}/benchTest`
_emptyDirSync(reportDirPath)
fs2.emptyDir(reportDirPath)

const r = await runBench({
fns: {
Expand All @@ -24,11 +24,11 @@ test('runBench', async () => {
immediate: expect.any(Number),
})

const summary = _readJsonSync(`${reportDirPath}/runBench.json`)
const summary = fs2.readJson(`${reportDirPath}/runBench.json`)
expect(summary).toMatchObject({
noop: expect.any(Number),
immediate: expect.any(Number),
})

expect(_pathExistsSync(`${reportDirPath}/runBench.svg`)).toBe(true)
expect(fs2.pathExists(`${reportDirPath}/runBench.svg`)).toBe(true)
}, 240000)
17 changes: 5 additions & 12 deletions src/bench.util.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { pDefer, _range } from '@naturalcycles/js-lib'
import {
_ensureDirSync,
_writeFileSync,
_writeJsonSync,
dimGrey,
yellow,
runScript,
} from '@naturalcycles/nodejs-lib'
import { dimGrey, yellow, runScript, fs2 } from '@naturalcycles/nodejs-lib'
import type { Event, Suite } from 'benchmark'
import Benchmark from 'benchmark'
import vega from 'vega'
Expand Down Expand Up @@ -65,21 +58,21 @@ export async function runBench(opt: RunBenchOptions): Promise<HertzMap> {
// summary[name] = results.hz.map(map => map[name]!)
// })

_ensureDirSync(reportDirPath)
fs2.ensureDir(reportDirPath)
const summaryJsonPath = `${reportDirPath}/${name}.json`
_writeJsonSync(summaryJsonPath, avg, { spaces: 2 })
fs2.writeJson(summaryJsonPath, avg, { spaces: 2 })
console.log(`saved ${dimGrey(summaryJsonPath)}`)
}

if (writePlot) {
_ensureDirSync(reportDirPath)
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`
_writeFileSync(plotPath, svg)
fs2.writeFile(plotPath, svg)
console.log(`saved ${dimGrey(plotPath)}`)
}

Expand Down
8 changes: 4 additions & 4 deletions src/cannon.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { pDelay } from '@naturalcycles/js-lib'
import { _emptyDirSync, _pathExistsSync, _readJsonSync } from '@naturalcycles/nodejs-lib'
import { fs2 } from '@naturalcycles/nodejs-lib'
import { expressFunctionFactory } from './cannon.profiles'
import { runCannon } from './cannon.util'
import { tmpDir } from './test/paths.cnst'

test('runCannon', async () => {
const reportDirPath = `${tmpDir}/cannonTest`
_emptyDirSync(reportDirPath)
fs2.emptyDir(reportDirPath)

await runCannon(
{
Expand All @@ -24,7 +24,7 @@ test('runCannon', async () => {
},
)

const summary = _readJsonSync<any>(`${reportDirPath}/Benchmark.summary.json`)
const summary = fs2.readJson<any>(`${reportDirPath}/Benchmark.summary.json`)
expect(summary[0]).toMatchObject({
name: 'noop',
rpsAvg: expect.any(Number),
Expand All @@ -40,5 +40,5 @@ test('runCannon', async () => {
name: 'async',
})

expect(_pathExistsSync(`${reportDirPath}/Benchmark.latencyAvg.svg`)).toBe(true)
expect(fs2.pathExists(`${reportDirPath}/Benchmark.latencyAvg.svg`)).toBe(true)
}, 240000)
22 changes: 7 additions & 15 deletions src/cannon.util.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import type { AddressInfo } from 'node:net'
import { pDefer, pDelay, pMap, StringMap, _omit, _range } from '@naturalcycles/js-lib'
import {
_ensureDirSync,
_writeFileSync,
_writeJsonSync,
runScript,
boldRed,
dimGrey,
yellow,
} from '@naturalcycles/nodejs-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'
Expand Down Expand Up @@ -74,7 +66,7 @@ export async function runCannon(
}

const { reportDirPath } = opt
_ensureDirSync(reportDirPath)
fs2.ensureDir(reportDirPath)

const resultByProfile: StringMap<AutocannonResult> = {}
const summaries: AutocannonSummary[] = []
Expand All @@ -92,12 +84,12 @@ export async function runCannon(

if (opt.writeSummary) {
const summaryJsonPath = `${reportDirPath}/${opt.name}.summary.json`
_writeJsonSync(summaryJsonPath, summaries, { spaces: 2 })
fs2.writeJson(summaryJsonPath, summaries, { spaces: 2 })
console.log(`saved ${dimGrey(summaryJsonPath)}`)
}

if (opt.writeRawSummary) {
_writeJsonSync(`${reportDirPath}/${opt.name}.rawSummary.json`, resultByProfile, { spaces: 2 })
fs2.writeJson(`${reportDirPath}/${opt.name}.rawSummary.json`, resultByProfile, { spaces: 2 })
}

if (opt.writePlots) {
Expand Down Expand Up @@ -194,7 +186,7 @@ async function writePlotFiles(
summaries: AutocannonSummary[],
): Promise<void> {
const { reportDirPath, name } = opt
_ensureDirSync(reportDirPath)
fs2.ensureDir(reportDirPath)

let fields = ['rpsAvg', 'latencyAvg', 'latency50', 'latency90', 'latency99', 'throughputAvg']
if (!opt.includeLatencyPercentiles) {
Expand All @@ -211,10 +203,10 @@ async function writePlotFiles(
const svg = await view.toSVG()
// console.log(svg)

_writeFileSync(`${reportDirPath}/${name}.${specName}.svg`, svg)
fs2.writeFile(`${reportDirPath}/${name}.${specName}.svg`, svg)
})

_writeFileSync(`${reportDirPath}/${name}.md`, mdContent(opt, Object.keys(specs)))
fs2.writeFile(`${reportDirPath}/${name}.md`, mdContent(opt, Object.keys(specs)))
}

function autocannonSummaryToVegaSpecs(
Expand Down
Loading

0 comments on commit 5e7c513

Please sign in to comment.