README
ΒΆ
TinyString Benchmark Suite
Automated benchmark tools to measure and compare performance between standard Go libraries and TinyString implementations.
Quick Usage π
# Run complete benchmark (recommended)
./build-and-measure.sh
# Clean generated files
./clean-all.sh
# Update README with existing data only (does not re-run benchmarks)
./update-readme.sh
# Run all memory and binary size benchmarks (without updating README)
./run-all-benchmarks.sh
# Run only memory benchmarks
./memory-benchmark.sh
What Gets Measured π
- Binary Size Comparison: Native + WebAssembly builds with multiple optimization levels. This compares the compiled output size of projects using the standard Go library versus TinyString.
- Memory Allocation: Measures Bytes/op, Allocations/op, and execution time (ns/op) for benchmark categories. This helps in understanding the memory efficiency of TinyString compared to standard library operations.
- String Processing: Benchmarks operations like case conversion, text manipulation, etc.
- Number Processing: Benchmarks numeric formatting, conversion operations, etc.
- Mixed Operations: Benchmarks scenarios involving a combination of string and numeric operations.
Current Performance Status
Target: Achieve memory usage close to standard library while maintaining binary size benefits.
Latest Results (Run ./build-and-measure.sh
to update):
- β Binary Size: TinyString is 20-50% smaller than stdlib for WebAssembly.
- β οΈ Memory Usage: Number Processing uses 1000% more memory (needs optimization).
π Memory Optimization Guide: See MEMORY_REDUCTION.md
for comprehensive techniques and best practices to replace Go standard libraries with TinyString's optimized implementations. Essential reading for efficient string and numeric processing in TinyGo WebAssembly applications.
Requirements
- Go 1.21+
- TinyGo (optional, but recommended for full WebAssembly testing and to achieve smallest binary sizes).
Directory Structure
benchmark/
βββ analyzer.go # Main analysis program for benchmark results.
βββ common.go # Shared utilities used by benchmark scripts and tools.
βββ reporter.go # Logic for updating the README.md with benchmark results.
βββ MEMORY_REDUCTION.md # Detailed guide for memory optimization techniques in TinyGo.
βββ build-and-measure.sh # Main script: builds, measures binary sizes, runs memory benchmarks, and updates README.md.
βββ memory-benchmark.sh # Script to run only memory allocation benchmarks.
βββ clean-all.sh # Script to clean all generated binaries and temporary files.
βββ update-readme.sh # Script to update benchmark sections in README.md using existing data (does not run new benchmarks).
βββ run-all-benchmarks.sh # Script to execute all benchmark tests (binary size and memory) without updating the README.md.
βββ bench-binary-size/ # Contains Go programs for binary size testing.
β βββ standard-lib/ # Example project using standard Go library.
β βββ tinystring-lib/ # Example project using TinyString library.
βββ bench-memory-alloc/ # Contains Go programs for memory allocation benchmarks.
βββ standard/ # Memory benchmark tests for standard Go library.
βββ tinystring/ # Memory benchmark tests for TinyString library.
βββ pointer-comparison/ # Specific tests for pointer optimization in TinyString.
What the Scripts Do
This section provides a clear explanation of each script's function, expected behavior, and typical use case.
build-and-measure.sh
- Purpose: This is the main, comprehensive benchmark script. It orchestrates the entire benchmarking process.
- Actions:
- Compiles example applications (both standard library and TinyString versions) using various TinyGo optimization levels (e.g., -ultra, -speed, -debug) if TinyGo is available.
- Measures the resulting binary sizes for both native and WebAssembly targets.
- Executes memory allocation benchmarks (delegating to
go test
with-benchmem
). - Calls
reporter.go
to update the main project'sREADME.md
(this file) with the latest binary size and memory allocation results.
- Output: Updates
README.md
with new data tables and summaries. Generates compiled binaries. - Use Case: Run this script to get a full performance overview and update the documentation with the latest figures.
memory-benchmark.sh
- Purpose: Executes only the memory allocation benchmarks.
- Actions:
- Navigates to the relevant benchmark directories (
bench-memory-alloc/standard
andbench-memory-alloc/tinystring
). - Runs
go test -bench=. -benchmem
to perform memory benchmarks. - The script itself does not directly update the README; results are typically fed into
reporter.go
bybuild-and-measure.sh
or can be analyzed manually.
- Navigates to the relevant benchmark directories (
- Output: Prints benchmark results (Bytes/op, Allocs/op, ns/op) to standard output.
- Use Case: Use this script when you specifically want to test memory performance without rebuilding binaries or updating the README. Useful for focused optimization efforts.
clean-all.sh
- Purpose: Cleans up files generated by the benchmark and build processes.
- Actions:
- Removes all compiled binaries (e.g.,
.exe
,.wasm
files) from benchmark directories. - Deletes temporary analysis files or other artifacts created during benchmarking.
- Removes all compiled binaries (e.g.,
- Output: A cleaner workspace, free of generated files.
- Use Case: Run this before a fresh benchmark run or to free up disk space.
update-readme.sh
- Purpose: Updates the benchmark sections in this
README.md
file using previously generated benchmark data. - Actions:
- Reads existing data files (if any, typically produced by
analyzer.go
after benchmarks have been run). - Calls
reporter.go
to re-format and insert this data into theREADME.md
.
- Reads existing data files (if any, typically produced by
- Important: This script does not re-run any benchmarks or re-compile any code. It only updates the documentation based on the last available data.
- Output: Modifies
README.md
if existing data is found. - Use Case: Use this if you have new benchmark data processed by
analyzer.go
and only want to update the README without running the fullbuild-and-measure.sh
script again.
run-all-benchmarks.sh
- Purpose: Executes all available benchmark tests (both binary size and memory allocation) but does not automatically update the
README.md
. - Actions:
- Performs binary builds and size measurements (similar to
build-and-measure.sh
but without the README update step). - Runs all memory allocation benchmarks (similar to
memory-benchmark.sh
).
- Performs binary builds and size measurements (similar to
- Output: Prints benchmark results to standard output and generates compiled binaries and potentially raw data files.
- Use Case: Useful for gathering all raw benchmark data for analysis without immediately changing the
README.md
. The results can then be used byupdate-readme.sh
or analyzed separately.
Example Output
π Starting binary size benchmark...
β
TinyGo found: tinygo version 0.37.0
π§Ή Cleaning previous files...
π¦ Building standard library example with multiple optimizations...
π¦ Building TinyString example with multiple optimizations...
π Analyzing sizes and updating README...
π§ Running memory allocation benchmarks...
β
Binary size analysis completed and README updated
β
Memory benchmarks completed and README updated
π Benchmark completed successfully!
π Generated files:
standard: 1.3MiB
tinystring: 1.1MiB
standard.wasm: 581KiB
tinystring.wasm: 230KiB
standard-ultra.wasm: 142KiB
tinystring-ultra.wasm: 23KiB
Troubleshooting
TinyGo Not Found:
β TinyGo is not installed. Building only standard Go binaries.
Install TinyGo from: https://tinygo.org/getting-started/install/
Permission Issues (Linux/macOS/WSL): If you encounter permission errors when trying to run the shell scripts, make them executable:
chmod +x *.sh
Build Failures:
- Ensure you're in the
benchmark/
directory - Verify TinyString library is available in the parent directory
Documentation
ΒΆ
There is no documentation for this package.