Why poly-bench
A multi-language benchmarking framework for fair cross-language comparisons
poly-bench is a multi-language benchmarking framework that lets you define benchmarks once and run them across Go, TypeScript, and Rust with unified output and fair comparisons.
.bench files) to define benchmarks that compile to native code in each target language.poly-bench provides everything you need for rigorous cross-language benchmarking:
| Feature | Description |
|---|---|
| Custom DSL | Write benchmarks in a clean, declarative syntax with language-specific setup blocks |
| Auto-calibration | Automatically adjusts iteration counts to reach target execution time |
| Memory profiling | Track allocations across Go, TypeScript, and Rust |
| Portable fixtures | Share hex-encoded test data across all language implementations |
| Chart generation | Generate SVG tables, pie charts, and speedup charts from results |
| LSP support | Full editor integration with diagnostics, completions, and formatting |
Imagine you're building a library that needs implementations in Go, TypeScript, and Rust. You want to know which is fastest for different operations. Today, you'd write:
1func BenchmarkKeccak(b *testing.B) {2 data := []byte("hello world")3 for i := 0; i < b.N; i++ {4 keccak256(data)5 }6}Three different APIs. Three different output formats. Three different iteration strategies. No easy way to compare.
With poly-bench, you write one .bench file:
1suite keccak {2 warmup: 1003 compare: true4 baseline: "go"5
6 setup go {7 import "golang.org/x/crypto/sha3"8 helpers {9 func keccak256(data []byte) []byte {10 h := sha3.NewLegacyKeccak256()11 h.Write(data)12 return h.Sum(nil)13 }14 }15 }16
17 setup ts {18 import { keccak256 } from 'viem';19 }20
21 setup rust {22 import { use tiny_keccak::{Hasher, Keccak}; }23 helpers {24 fn keccak256(data: &[u8]) -> [u8; 32] {25 let mut hasher = Keccak::v256();26 let mut output = [0u8; 32];27 hasher.update(data);28 hasher.finalize(&mut output);29 output30 }31 }32 }33
34 fixture data {35 hex: "68656c6c6f20776f726c64"36 }37
38 bench keccak256 {39 go: keccak256(data)40 ts: keccak256(data)41 rust: keccak256(&data)42 }43}Run poly-bench run and get unified results across all three languages with automatic comparison tables.
poly-bench was built with these principles in mind:
The .bench file format is the source of truth. It's designed to be readable, version-controllable, and language-agnostic while supporting language-specific setup when needed.
The DSL compiles to an intermediate representation (IR) that can generate code for any supported language. This ensures consistent behavior and makes adding new languages straightforward.
Each language runs in its own isolated environment:
runtime.ReadMemStats for memory trackingprocess.memoryUsage()poly-bench includes proper statistical methodology:
Ready to benchmark across languages? Head to the Getting Started guide to set up your first poly-bench project.