Skip to content

Instantly share code, notes, and snippets.

@DeedleFake
Last active September 2, 2024 20:56
Show Gist options
  • Save DeedleFake/34eb73a2be5415e2d7b8dc4fdbafe936 to your computer and use it in GitHub Desktop.
Save DeedleFake/34eb73a2be5415e2d7b8dc4fdbafe936 to your computer and use it in GitHub Desktop.
Benchmarks of pull and push iterators in Go.

A simple benchmark comparing push and pull iterators to each other and also comparing them to themselves with and without PGO.

Results

goos: linux
goarch: amd64
pkg: test
cpu: AMD Ryzen 9 3900X 12-Core Processor
        │ no-pgo.txt  │              pgo.txt               │
        │   sec/op    │   sec/op     vs base               │
Push-24   116.5n ± 6%   107.4n ± 2%  -7.77% (p=0.000 n=10)
Pull-24   2.047µ ± 2%   1.994µ ± 7%  -2.57% (p=0.009 n=10)
geomean   488.2n        462.8n       -5.20%

        │ no-pgo.txt │               pgo.txt               │
        │    B/op    │    B/op     vs base                 │
Push-24   24.00 ± 0%   24.00 ± 0%       ~ (p=1.000 n=10) ¹
Pull-24   352.0 ± 0%   352.0 ± 0%       ~ (p=1.000 n=10) ¹
geomean   91.91        91.91       +0.00%
¹ all samples are equal

        │ no-pgo.txt │               pgo.txt               │
        │ allocs/op  │ allocs/op   vs base                 │
Push-24   2.000 ± 0%   2.000 ± 0%       ~ (p=1.000 n=10) ¹
Pull-24   12.00 ± 0%   12.00 ± 0%       ~ (p=1.000 n=10) ¹
geomean   4.899        4.899       +0.00%
¹ all samples are equal
module test
go 1.23.0
package iter_test
import (
"iter"
"slices"
"testing"
)
var values = slices.Values([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
func BenchmarkPush(b *testing.B) {
for range b.N {
for v := range values {
_ = v
}
}
}
func BenchmarkPull(b *testing.B) {
for range b.N {
next, stop := iter.Pull(values)
for {
_, ok := next()
if !ok {
break
}
}
stop()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment