Skip to content

Commit

Permalink
metrics: fix issues with benchmarks (ethereum#30667)
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan committed Dec 10, 2024
1 parent 5f1e8ef commit 6b90f70
Showing 1 changed file with 1 addition and 31 deletions.
32 changes: 1 addition & 31 deletions metrics/sample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package metrics
import (
"math"
"math/rand"
"runtime"
"testing"
"time"
)
Expand All @@ -27,6 +26,7 @@ func BenchmarkCompute1000(b *testing.B) {
SampleVariance(mean, s)
}
}

func BenchmarkCompute1000000(b *testing.B) {
s := make([]int64, 1000000)
var sum int64
Expand All @@ -40,28 +40,6 @@ func BenchmarkCompute1000000(b *testing.B) {
SampleVariance(mean, s)
}
}
func BenchmarkCopy1000(b *testing.B) {
s := make([]int64, 1000)
for i := 0; i < len(s); i++ {
s[i] = int64(i)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
sCopy := make([]int64, len(s))
copy(sCopy, s)
}
}
func BenchmarkCopy1000000(b *testing.B) {
s := make([]int64, 1000000)
for i := 0; i < len(s); i++ {
s[i] = int64(i)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
sCopy := make([]int64, len(s))
copy(sCopy, s)
}
}

func BenchmarkExpDecaySample257(b *testing.B) {
benchmarkSample(b, NewExpDecaySample(257, 0.015))
Expand Down Expand Up @@ -237,17 +215,9 @@ func TestUniformSampleStatistics(t *testing.T) {
}

func benchmarkSample(b *testing.B, s Sample) {
var memStats runtime.MemStats
runtime.ReadMemStats(&memStats)
pauseTotalNs := memStats.PauseTotalNs
b.ResetTimer()
for i := 0; i < b.N; i++ {
s.Update(1)
}
b.StopTimer()
runtime.GC()
runtime.ReadMemStats(&memStats)
b.Logf("GC cost: %d ns/op", int(memStats.PauseTotalNs-pauseTotalNs)/b.N)
}

func testExpDecaySampleStatistics(t *testing.T, s SampleSnapshot) {
Expand Down

0 comments on commit 6b90f70

Please sign in to comment.