Skip to content

Commit

Permalink
add a few additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sean- committed Dec 14, 2023
1 parent c30d394 commit 3f4726c
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 9 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,19 @@ $ go test -test.bench=. -benchmem
goos: darwin
goarch: arm64
pkg: github.com/sean-/bench-go-histograms
Benchmark_CircLLHistDuration-10 7262088 166.8 ns/op 0 B/op 0 allocs/op
Benchmark_PromDuration-10 4536674 281.2 ns/op 0 B/op 0 allocs/op
Benchmark_CircLLHistDuration-10 7221150 149.7 ns/op 0 B/op 0 allocs/op
Benchmark_CircLLHistApproxSum/ApproxSum-10 1000000000 0.0000002 ns/op 0 B/op 0 allocs/op
Benchmark_CircLLHistBinCount/BinCount-10 1000000000 0.0000001 ns/op 0 B/op 0 allocs/op
Benchmark_CircLLHistBuckets/Count-10 1000000000 0.0000000 ns/op 0 B/op 0 allocs/op
Benchmark_CircLLHistMerge/Merge-10 8280682 142.6 ns/op 0 B/op 0 allocs/op
Benchmark_CircLLHistQuantile/ValueAtQuantile-10 1000000000 0.0000005 ns/op 0 B/op 0 allocs/op
Benchmark_PromDuration-10 2781200 422.3 ns/op 0 B/op 0 allocs/op
Benchmark_PromApproxSum/SampleSum-10 1000000000 0.0000015 ns/op 0 B/op 0 allocs/op
Benchmark_PromApproxCount/SampleCount-10 1000000000 0.0000059 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/sean-/bench-go-histograms 3.382s
ok github.com/sean-/bench-go-histograms 4.399s
bench-go-histograms on  main [!?] via 🐹 v1.21.5 using ☁️ default/cockroach-ephemeral took 4.8s
$ go version
go version go1.21.5 darwin/arm64
```
148 changes: 142 additions & 6 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/jaswdr/faker"
"github.com/openhistogram/circonusllhist"
"github.com/prometheus/client_golang/prometheus"
prometheusgo "github.com/prometheus/client_model/go"
)

const (
Expand All @@ -22,37 +23,172 @@ func randDuration(f *faker.Faker, min, max time.Duration) time.Duration {
}

func Benchmark_CircLLHistDuration(b *testing.B) {
h := circonusllhist.New()
h1 := circonusllhist.New()
f := faker.NewWithSeed(rand.NewSource(randSeed))

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
h.RecordDuration(randDuration(&f, minTime, maxTime))
h1.RecordDuration(randDuration(&f, minTime, maxTime))
}
})
}

func Benchmark_CircLLHistApproxSum(b *testing.B) {
h1 := circonusllhist.New()
src := rand.NewSource(randSeed)
rnd := rand.New(src)
f := faker.NewWithSeed(rnd)

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
h1.RecordDuration(randDuration(&f, minTime, maxTime))
}
})

b.Run("ApproxSum", func(b *testing.B) {
_ = h1.ApproxSum()
})
}

func Benchmark_CircLLHistBinCount(b *testing.B) {
h1 := circonusllhist.New()
src := rand.NewSource(randSeed)
rnd := rand.New(src)
f := faker.NewWithSeed(rnd)

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
h1.RecordDuration(randDuration(&f, minTime, maxTime))
}
})

b.Run("BinCount", func(b *testing.B) {
_ = h1.BinCount()
})
}

func Benchmark_CircLLHistBuckets(b *testing.B) {
h1 := circonusllhist.New()
src := rand.NewSource(randSeed)
rnd := rand.New(src)
f := faker.NewWithSeed(rnd)

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
h1.RecordDuration(randDuration(&f, minTime, maxTime))
}
})

b.Run("Count", func(b *testing.B) {
_ = h1.Count()
})
}

func Benchmark_CircLLHistMerge(b *testing.B) {
h1 := circonusllhist.New()
h2 := circonusllhist.New()
f := faker.NewWithSeed(rand.NewSource(randSeed))

b.Run("Merge", func(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
h2.RecordDuration(randDuration(&f, minTime, maxTime))
}
})

h1.Merge(h2)
h2.Reset()
})
}

func Benchmark_CircLLHistQuantile(b *testing.B) {
h1 := circonusllhist.New()
src := rand.NewSource(randSeed)
rnd := rand.New(src)
f := faker.NewWithSeed(rnd)

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
h1.RecordDuration(randDuration(&f, minTime, maxTime))
}
})

b.Run("ValueAtQuantile", func(b *testing.B) {
h1.ValueAtQuantile(rnd.Float64())
})
}

// func Benchmark_CircLLHistDurationNoLookup(b *testing.B) {
// h := circonusllhist.NewNoLocks()
// h1 := circonusllhist.NewNoLocks()
// f := faker.NewWithSeed(rand.NewSource(randSeed))

// b.RunParallel(func(pb *testing.PB) {
// for pb.Next() {
// d := randDuration(&f, minTime, maxTime)
// h.RecordDuration(d)
// h1.RecordDuration(d)
// }
// })
// }

func Benchmark_PromDuration(b *testing.B) {
h := prometheus.NewHistogram(prometheus.HistogramOpts{
h1 := prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "bench_prom_dur_hist",
})
f := faker.NewWithSeed(rand.NewSource(randSeed))

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
h.Observe(randDuration(&f, minTime, maxTime).Seconds())
h1.Observe(randDuration(&f, minTime, maxTime).Seconds())
}
})
}

func Benchmark_PromApproxSum(b *testing.B) {
src := rand.NewSource(randSeed)
rnd := rand.New(src)
f := faker.NewWithSeed(rnd)
h1 := prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "bench_prom_dur_hist",
})

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
h1.Observe(randDuration(&f, minTime, maxTime).Seconds())
}
})

m := &prometheusgo.Metric{}
b.Run("SampleSum", func(b *testing.B) {
if err := h1.Write(m); err != nil {
_ = err // b.Skip()
}
if m.Histogram.SampleSum != nil {
_ = m.Histogram.SampleSum
}
})
}

func Benchmark_PromApproxCount(b *testing.B) {
src := rand.NewSource(randSeed)
rnd := rand.New(src)
f := faker.NewWithSeed(rnd)
h1 := prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "bench_prom_dur_hist",
})

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
h1.Observe(randDuration(&f, minTime, maxTime).Seconds())
}
})

m := &prometheusgo.Metric{}
b.Run("SampleCount", func(b *testing.B) {
if err := h1.Write(m); err != nil {
_ = err // b.Skip()
}
if m.Histogram.SampleCount != nil {
_ = m.Histogram.SampleCount
}
})
}

0 comments on commit 3f4726c

Please sign in to comment.