From d61cc6c9bff73bd5047bdbda70eead9ec5ce9ed6 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Thu, 21 Dec 2023 20:59:45 -0300 Subject: [PATCH] just benchmark --- benchmark.ts | 10 +++++----- justfile | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/benchmark.ts b/benchmark.ts index 82703f2..4e4c8fc 100644 --- a/benchmark.ts +++ b/benchmark.ts @@ -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])) } @@ -56,7 +56,7 @@ const benchmarks: Record Promise; 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() diff --git a/justfile b/justfile index e427cf5..2be925c 100644 --- a/justfile +++ b/justfile @@ -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