benchmark

command
v0.25.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README ΒΆ

fmt Benchmark Suite

Automated benchmark tools to measure and compare performance between standard Go libraries and fmt implementations.

Binary Size Comparison

Standard Library Example | fmt Example

Last updated: 2026-06-18 13:13:20

Build Type Parameters Standard Library
go build
fmt
tinygo build
Size Reduction Performance
πŸ–₯️ Default Native -ldflags="-s -w" 1.4 MB 1.3 MB -156.0 KB βž– 10.5%
🌐 Default WASM (default -opt=z) 697.2 KB 284.5 KB -412.7 KB βœ… 59.2%
🌐 Ultra WASM -no-debug -panic=trap -scheduler=none -gc=leaking -target wasm 156.0 KB 24.7 KB -131.4 KB πŸ† 84.2%
🌐 Speed WASM -opt=2 -target wasm 948.5 KB 408.5 KB -540.0 KB βœ… 56.9%
🌐 Debug WASM -opt=0 -target wasm 1.9 MB 818.7 KB -1.1 MB βœ… 58.6%
🎯 Performance Summary
  • πŸ† Peak Reduction: 84.2% (Best optimization)
  • βœ… Average WebAssembly Reduction: 64.7%
  • βœ… Average Native Reduction: 10.5%
  • πŸ“¦ Total Size Savings: 2.3 MB across all builds
Performance Legend
  • ❌ Poor (<5% reduction)
  • βž– Fair (5-15% reduction)
  • βœ… Good (15-70% reduction)
  • πŸ† Outstanding (>70% reduction)

Memory Usage Comparison

Standard Library Example | fmt Example

Last updated: 2026-06-18 13:13:35

Performance benchmarks comparing memory allocation patterns between standard Go library and fmt:

πŸ§ͺ Benchmark Category πŸ“š Library πŸ’Ύ Memory/Op πŸ”’ Allocs/Op ⏱️ Time/Op πŸ“ˆ Memory Trend 🎯 Alloc Trend πŸ† Performance
πŸ“ String Processing πŸ“Š Standard 808 B / 596.048 OP 32 2.2ΞΌs - - -
πŸš€ fmt 464 B / 218.416 OP 17 5.4ΞΌs πŸ† 42.6% less πŸ† 46.9% less πŸ† Excellent
πŸ”’ Number Processing πŸ“Š Standard 720 B / 566.374 OP 34 2.3ΞΌs - - -
πŸš€ fmt 320 B / 567.528 OP 17 2.0ΞΌs πŸ† 55.6% less πŸ† 50.0% less πŸ† Excellent
πŸ”„ Mixed Operations πŸ“Š Standard 368 B / 713.047 OP 20 1.4ΞΌs - - -
πŸš€ fmt 192 B / 444.537 OP 12 2.6ΞΌs πŸ† 47.8% less πŸ† 40.0% less πŸ† Excellent
🎯 Performance Summary
  • πŸ’Ύ Memory Efficiency: πŸ† Excellent (Lower memory usage) (-48.7% average change)
  • πŸ”’ Allocation Efficiency: πŸ† Excellent (Fewer allocations) (-45.6% average change)
  • πŸ“Š Benchmarks Analyzed: 3 categories
  • 🎯 Optimization Focus: Binary size reduction vs runtime efficiency
βš–οΈ Trade-offs Analysis

The benchmarks reveal important trade-offs between binary size and runtime performance:

πŸ“¦ Binary Size Benefits βœ…
  • πŸ† 16-84% smaller compiled binaries
  • 🌐 Superior WebAssembly compression ratios
  • πŸš€ Faster deployment and distribution
  • πŸ’Ύ Lower storage requirements
🧠 Runtime Memory Considerations ⚠️
  • πŸ“ˆ Higher allocation overhead during execution
  • πŸ—‘οΈ Increased GC pressure due to allocation patterns
  • ⚑ Trade-off optimizes for distribution size over runtime efficiency
  • πŸ”„ Different optimization strategy than standard library
🎯 Optimization Recommendations
🎯 Use Case πŸ’‘ Recommendation πŸ”§ Best For
🌐 WebAssembly Apps βœ… fmt Size-critical web deployment
πŸ“± Embedded Systems βœ… fmt Resource-constrained devices
☁️ Edge Computing βœ… fmt Fast startup and deployment
🏒 Memory-Intensive Server ⚠️ Standard Library High-throughput applications
πŸ”„ High-Frequency Processing ⚠️ Standard Library Performance-critical workloads
πŸ“Š Performance Legend
  • πŸ† Excellent (Better performance)
  • βœ… Good (Acceptable trade-off)
  • ⚠️ Caution (Higher resource usage)
  • ❌ Poor (Significant overhead)

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 πŸ“Š

  1. Binary Size Comparison: Native + WebAssembly builds with multiple optimization levels. This compares the compiled output size of projects using the standard Go library versus fmt.
  2. Memory Allocation: Measures Bytes/op, Allocations/op, and execution time (ns/op) for benchmark categories. This helps in understanding the memory efficiency of fmt 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: fmt 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 fmt'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).

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 fmt library is available in the parent directory

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL