Comprehensive benchmarking tool to compare binary size, latency, memory usage, and throughput between aisdk and rig Rust AI libraries.
-
Copy
.env.exampleto.envand add your OpenAI API key:cp .env.example .env # Edit .env and set OPENAI_API_KEY -
Build and run benchmarks with specific feature flags
The benchmark suite supports the following feature flags for isolation:
aisdk-qa- Basic Q&A without streamingaisdk-qa-streaming- Streaming Q&A responsesaisdk-embedding- Basic embedding generationaisdk-embedding-full- Full embedding with feature enabled
rig-qa- Basic Q&A without streamingrig-qa-streaming- Streaming Q&A responsesrig-embedding- Basic embedding generationrig-embedding-full- Full embedding with feature enabled
Run a single benchmark:
cargo run --release --features aisdk-qaRun multiple scenarios:
cargo run --release --features aisdk-qa,aisdk-qa-streaming,aisdk-embedding,aisdk-embedding-fullCompare libraries:
cargo run --release --features aisdk-qa,rig-qaFull benchmark suite:
cargo run --release --all-featuresThe benchmark produces two outputs:
-
Human-readable table printed to stdout showing:
- Scenario name
- Library (aisdk/rig)
- Scenario type (Basic Q&A, Streaming, Embedding, etc.)
- Latency (ms)
- Memory peak (MB)
- Throughput (ops/sec)
- Binary size (MB)
-
JSON file (
benchmark_results.json) for programmatic analysis
- Latency (ms): Total wall-clock time for the operation
- Memory (MB): Peak resident set size during execution
- Throughput (ops/sec): Operations per second (1/latency)
- Binary Size (MB): Release binary size on disk
- Rust 1.70+
- OpenAI API key
- Linux/macOS/Windows with
sysinfosupport
- Each feature flag ensures only the specified library is compiled into the binary, allowing for accurate binary size comparisons
- Binary size includes all dependencies required by each library
- Memory measurements use platform-specific implementations
- Latency is measured using wall-clock time for the entire operation including network I/O