In continuation of the message processing comparisons yesterday, the benchmarks below performed additional tests.
Based on the benchmark:
- There is less allocated bytes and instances per operation with preallocated version (
B/opandallocs/op) - There is less time to process each operation and higher throughput with preallocated version (
sec/opandB/s)
go test -run '^$' \
-bench '^BenchmarkBuildMessageBatch$' \
-count=10 \
> /tmp/codec01-message-batch.txt
benchstat \
-filter '.unit:(B/op OR allocs/op)' \
-col /implementation \
-row .name \
/tmp/codec01-message-batch.txt
goos: linux
goarch: arm64
pkg: codec01
│ growing │ preallocated │
│ B/op │ B/op vs base │
BuildMessageBatch 278.69Ki ± 0% 64.00Ki ± 0% -77.04% (p=0.000 n=10)
│ growing │ preallocated │
│ allocs/op │ allocs/op vs base │
BuildMessageBatch 19.000 ± 0% 1.000 ± 0% -94.74% (p=0.000 n=10)
benchstat \
-filter '.unit:(ns/op OR MB/s)' \
-col /implementation \
-row .name \
/tmp/codec01-message-batch.txt
goos: linux
goarch: arm64
pkg: codec01
│ growing │ preallocated │
│ sec/op │ sec/op vs base │
BuildMessageBatch 62.29µ ± 14% 14.73µ ± 7% -76.35% (p=0.000 n=10)
│ growing │ preallocated │
│ B/s │ B/s vs base │
BuildMessageBatch 980.0Mi ± 12% 4144.2Mi ± 7% +322.87% (p=0.000 n=10)