Skip to content

Commit

Permalink
just benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Dec 21, 2023
1 parent d7dad8e commit d61cc6c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 5 additions & 5 deletions benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import { AbstractRelay } from './abstract-relay.ts'
import { Relay as PureRelay } from './relay.ts'
import { alwaysTrue } from './helpers.ts'

const RUNS = 400
const EVENTS = 1000

let messages: string[] = []
let baseContent = ''
for (let i = 0; i < RUNS; i++) {
for (let i = 0; i < EVENTS; i++) {
baseContent += 'a'
}
const secretKey = generateSecretKey()
for (let i = 0; i < RUNS / 100; i++) {
for (let i = 0; i < EVENTS / 200; i++) {
const tags = []
for (let t = 0; t < i; t++) {
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)
messages.push(JSON.stringify(['EVENT', '_', signed]))
}
Expand Down Expand Up @@ -56,7 +56,7 @@ const benchmarks: Record<string, { test: () => Promise<void>; runs: number[] }>
wasm: { test: run(wasmRelay), runs: [] },
}

for (let b = 0; b < 50; b++) {
for (let b = 0; b < 20; b++) {
for (let name in benchmarks) {
const { test, runs } = benchmarks[name]
const before = performance.now()
Expand Down
7 changes: 7 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ format:
lint:
eslint --ext .ts *.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

0 comments on commit d61cc6c

Please sign in to comment.