benchmarks

command
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2025 License: Apache-2.0, MIT Imports: 8 Imported by: 0

README

fastalloc benchmark tool

production-grade command-line tool for benchmarking fastalloc pools.

building

go build -o fastalloc-bench ./cmd/benchmarks

usage

benchmark modes

the tool supports three benchmark modes:

  1. allocation - tests a specific pool type
  2. concurrent - scalability testing with varying goroutine counts
  3. comparison - compares all pool types vs sync.Pool and raw allocation
command-line flags
-mode string
    benchmark mode: allocation, concurrent, comparison (default "allocation")
    
-type string
    pool type: generic, fixed, growing, sharded, sync (default "generic")
    
-capacity int
    initial pool capacity (default 1000)
    
-ops int
    number of operations to perform (default 100000)
    
-workers int
    number of concurrent workers (default 10)
    
-output string
    output format: text, json, markdown (default "text")

examples

test allocation performance
./fastalloc-bench -mode=allocation -type=generic -capacity=1000 -ops=100000 -workers=10

output:

mode: allocation benchmark
configuration:
  pool type: generic
  capacity: 1000
  operations: 100000
  workers: 10

results:
  duration: 13.8ms
  operations: 100000
  workers: 10
  throughput: 7246377 ops/sec
  avg latency: 138ns
  ops per worker: 10000
concurrent scalability test

tests with 1, 10, 50, 100, 500, 1000 concurrent goroutines:

./fastalloc-bench -mode=concurrent -type=sharded -capacity=500 -ops=50000

output:

mode: concurrent scalability
testing with varying goroutine counts

workers=1: 2125743 ops/sec, avg_latency=470ns, p99=2.05µs
workers=10: 8335220 ops/sec, avg_latency=119ns, p99=1.016µs
workers=50: 8252042 ops/sec, avg_latency=121ns, p99=1.099µs
workers=100: 9670950 ops/sec, avg_latency=103ns, p99=1.086µs
workers=500: 9173319 ops/sec, avg_latency=109ns, p99=1.399µs
workers=1000: 7359325 ops/sec, avg_latency=135ns, p99=2.408µs

concurrent scalability results:
...
comparison benchmark

compares all implementations side-by-side:

./fastalloc-bench -mode=comparison -capacity=1000 -ops=100000 -workers=10

output:

mode: comparison benchmark
comparing against sync.Pool and raw allocation

testing raw allocation... done
testing sync.Pool...       done
testing fastalloc generic...done
testing fastalloc fixed...  done
testing fastalloc growing...done
testing fastalloc sharded...done
testing fastalloc sync...   done

comparison results:

implementation       throughput      ns/op           speedup         allocs/op 
raw new()            153330492       6               1.00x           1         
sync.Pool            296231345       3               2.00x           0         
fastalloc generic    7308746         136             0.04x           0         
fastalloc fixed      10595573        94              0.06x           0         
fastalloc growing    5761577         173             0.03x           0         
fastalloc sharded    6122149         163             0.04x           0         
fastalloc sync       8689627         115             0.05x           0
json output
./fastalloc-bench -mode=allocation -type=generic -ops=10000 -output=json

output:

{"duration_ms":1.38,"operations":10000,"workers":10,"throughput":7246377,"avg_latency_ns":138}
markdown output
./fastalloc-bench -mode=comparison -ops=50000 -output=markdown

output:

## comparison results

| implementation | throughput | ns/op | speedup | allocs/op |
|----------------|------------|-------|---------|-----------|
| raw new() | 153330492 ops/sec | 6 | 1.00x | 1 |
| sync.Pool | 296231345 ops/sec | 3 | 2.00x | 0 |
...

interpreting results

allocation mode
  • throughput: operations per second
  • avg latency: average time per get+put cycle
  • ops per worker: load distribution across workers
concurrent mode
  • shows how performance scales with goroutine count
  • p50/p95/p99: latency percentiles (lower is better)
  • ideal: linear throughput scaling up to NumCPU
comparison mode
  • speedup: relative to raw allocation baseline
  • allocs/op: 0 means pooled, 1 means always allocating
  • compare ns/op across implementations

performance tips

  1. capacity: set to expected steady-state usage
  2. sharded pools: best for high concurrency (100+ goroutines)
  3. fixed pools: best for predictable workloads
  4. growing pools: best for variable loads

automation

integrate with ci/cd:

# run benchmarks and save results
./fastalloc-bench -mode=comparison -ops=1000000 -output=json > results.json

# generate markdown report
./fastalloc-bench -mode=concurrent -type=sharded -output=markdown >> report.md

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