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:
- String Processing: Basic string operations (case conversion, manipulation)
- Number Processing: Numeric formatting and conversion operations
- Mixed Operations: Combined string and numeric operations
- JSON Operations: JSON marshaling and unmarshaling operations
- Complex nested structures
- Batch processing with different sizes
- Error handling scenarios
JSON Benchmarks Overview
The JSON benchmarking system is located in bench-memory-alloc/json-comparison/ and consists of:
data.go: Contains test data structures and generation logicmain_test.go: Core benchmarking functions for marshaling/unmarshalingerrors_test.go: Error case handling testsREADME.md: Detailed documentation for JSON benchmark suite
For specific implementation details and examples, refer to the documentation in the JSON comparison directory.
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).
- π JSON Performance:
- β Marshal: 25-30% better performance and memory usage
- β οΈ Unmarshal: 50% higher memory usage and slower processing
- π― Error Handling: Mixed results (better for Marshal, worse for Unmarshal)
π 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 comprehensive script: compiles apps with TinyGo optimizations,
β # measures binary sizes (native + WebAssembly), runs memory benchmarks,
β # and updates README.md with latest results. Use for full performance overview.
βββ memory-benchmark.sh # Executes only memory allocation benchmarks without building binaries.
β # Runs 'go test -bench=. -benchmem' in standard/tinystring directories.
β # Useful for focused memory optimization efforts.
βββ clean-all.sh # Removes compiled binaries (.exe, .wasm) and temporary analysis files.
β # Run before fresh benchmark runs or to free disk space.
βββ update-readme.sh # Updates README.md benchmark sections using existing data only.
β # Does NOT re-run benchmarks or recompile code. Only reformats/inserts
β # previously generated data into documentation.
βββ run-all-benchmarks.sh # Executes all benchmark tests (binary size + memory allocation) but
β # does NOT update README.md. Generates raw data for manual analysis.
βββ 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.
βββ json-comparison/ # JSON functionality benchmarks.
βββ data.go # Test data structures and JSON generators.
βββ main_test.go # Core marshal/unmarshal benchmarks.
βββ errors_test.go # Error handling benchmarks.
βββ README.md # JSON benchmark documentation.
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
π Latest Results: See generated benchmark reports in respective test directories
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.