just benchmark

This commit is contained in:
fiatjaf
2023-12-21 20:59:45 -03:00
parent d7dad8e204
commit d61cc6c9bf
2 changed files with 12 additions and 5 deletions

View File

@@ -6,20 +6,20 @@ import { AbstractRelay } from './abstract-relay.ts'
import { Relay as PureRelay } from './relay.ts' import { Relay as PureRelay } from './relay.ts'
import { alwaysTrue } from './helpers.ts' import { alwaysTrue } from './helpers.ts'
const RUNS = 400 const EVENTS = 1000
let messages: string[] = [] let messages: string[] = []
let baseContent = '' let baseContent = ''
for (let i = 0; i < RUNS; i++) { for (let i = 0; i < EVENTS; i++) {
baseContent += 'a' baseContent += 'a'
} }
const secretKey = generateSecretKey() const secretKey = generateSecretKey()
for (let i = 0; i < RUNS / 100; i++) { for (let i = 0; i < EVENTS / 200; i++) {
const tags = [] const tags = []
for (let t = 0; t < i; t++) { for (let t = 0; t < i; t++) {
tags.push(['t', 'nada']) tags.push(['t', 'nada'])
} }
const event = { created_at: Math.round(Date.now()) / 1000, kind: 1, content: baseContent.slice(0, RUNS - i), tags } const event = { created_at: Math.round(Date.now()) / 1000, kind: 1, content: baseContent.slice(0, EVENTS - i), tags }
const signed = finalizeEvent(event, secretKey) const signed = finalizeEvent(event, secretKey)
messages.push(JSON.stringify(['EVENT', '_', signed])) messages.push(JSON.stringify(['EVENT', '_', signed]))
} }
@@ -56,7 +56,7 @@ const benchmarks: Record<string, { test: () => Promise<void>; runs: number[] }>
wasm: { test: run(wasmRelay), runs: [] }, wasm: { test: run(wasmRelay), runs: [] },
} }
for (let b = 0; b < 50; b++) { for (let b = 0; b < 20; b++) {
for (let name in benchmarks) { for (let name in benchmarks) {
const { test, runs } = benchmarks[name] const { test, runs } = benchmarks[name]
const before = performance.now() const before = performance.now()

View File

@@ -23,3 +23,10 @@ format:
lint: lint:
eslint --ext .ts *.ts eslint --ext .ts *.ts
prettier --check *.ts prettier --check *.ts
benchmark:
bun build --target=node --outfile=bench.js benchmark.ts
bun run benchmark.ts
timeout 2s deno run bench.js || true
timeout 2s node bench.js || true
rm bench.js