benchmarks: SetBytes takes bytes per operation

Where the code was multiplying bytes by number of operations, this
resulted in absurdly high throughput numbers.

Also, in `BenchmarkParse()`, don't run the `expfmt` case twice.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2022-09-21 15:31:37 +00:00 committed by Julien Pivotto
parent c8786974d1
commit 8120af22e2
3 changed files with 10 additions and 7 deletions

View file

@ -367,7 +367,7 @@ func BenchmarkParse(b *testing.B) {
b.Run(parserName+"/no-decode-metric/"+fn, func(b *testing.B) { b.Run(parserName+"/no-decode-metric/"+fn, func(b *testing.B) {
total := 0 total := 0
b.SetBytes(int64(len(buf) * (b.N / promtestdataSampleCount))) b.SetBytes(int64(len(buf) / promtestdataSampleCount))
b.ReportAllocs() b.ReportAllocs()
b.ResetTimer() b.ResetTimer()
@ -395,7 +395,7 @@ func BenchmarkParse(b *testing.B) {
b.Run(parserName+"/decode-metric/"+fn, func(b *testing.B) { b.Run(parserName+"/decode-metric/"+fn, func(b *testing.B) {
total := 0 total := 0
b.SetBytes(int64(len(buf) * (b.N / promtestdataSampleCount))) b.SetBytes(int64(len(buf) / promtestdataSampleCount))
b.ReportAllocs() b.ReportAllocs()
b.ResetTimer() b.ResetTimer()
@ -428,7 +428,7 @@ func BenchmarkParse(b *testing.B) {
total := 0 total := 0
res := make(labels.Labels, 0, 5) res := make(labels.Labels, 0, 5)
b.SetBytes(int64(len(buf) * (b.N / promtestdataSampleCount))) b.SetBytes(int64(len(buf) / promtestdataSampleCount))
b.ReportAllocs() b.ReportAllocs()
b.ResetTimer() b.ResetTimer()
@ -458,7 +458,10 @@ func BenchmarkParse(b *testing.B) {
_ = total _ = total
}) })
b.Run("expfmt-text/"+fn, func(b *testing.B) { b.Run("expfmt-text/"+fn, func(b *testing.B) {
b.SetBytes(int64(len(buf) * (b.N / promtestdataSampleCount))) if parserName != "prometheus" {
b.Skip()
}
b.SetBytes(int64(len(buf) / promtestdataSampleCount))
b.ReportAllocs() b.ReportAllocs()
b.ResetTimer() b.ResetTimer()
@ -507,7 +510,7 @@ func BenchmarkGzip(b *testing.B) {
k := b.N / promtestdataSampleCount k := b.N / promtestdataSampleCount
b.ReportAllocs() b.ReportAllocs()
b.SetBytes(int64(k) * int64(n)) b.SetBytes(int64(n) / promtestdataSampleCount)
b.ResetTimer() b.ResetTimer()
total := 0 total := 0

View file

@ -176,7 +176,7 @@ func BenchmarkBufferedSeriesIterator(b *testing.B) {
// Simulate a 5 minute rate. // Simulate a 5 minute rate.
it := NewBufferIterator(newFakeSeriesIterator(int64(b.N), 30), 5*60) it := NewBufferIterator(newFakeSeriesIterator(int64(b.N), 30), 5*60)
b.SetBytes(int64(b.N * 16)) b.SetBytes(16)
b.ReportAllocs() b.ReportAllocs()
b.ResetTimer() b.ResetTimer()

View file

@ -75,7 +75,7 @@ func BenchmarkMemoizedSeriesIterator(b *testing.B) {
// Simulate a 5 minute rate. // Simulate a 5 minute rate.
it := NewMemoizedIterator(newFakeSeriesIterator(int64(b.N), 30), 5*60) it := NewMemoizedIterator(newFakeSeriesIterator(int64(b.N), 30), 5*60)
b.SetBytes(int64(b.N * 16)) b.SetBytes(16)
b.ReportAllocs() b.ReportAllocs()
b.ResetTimer() b.ResetTimer()