Permalink
Browse files

Correct the benchmarks

  • Loading branch information...
RussellLuo committed Oct 12, 2018
1 parent 7c16625 commit 52de9bed217582562a8b715b08c41dce7167b710
Showing with 42 additions and 82 deletions.
  1. +10 −12 README.md
  2. +32 −70 timingwheel_benchmark_test.go
View
@@ -29,18 +29,16 @@ $ go test -bench=.
goos: darwin
goarch: amd64
pkg: github.com/RussellLuo/timingwheel
BenchmarkTimingWheel_StartStop_1millionTimers_WithSameDurations-8 1000000 314 ns/op
BenchmarkStandardTimer_StartStop_1millionTimers_WithSameDurations-8 1000000 233 ns/op
BenchmarkTimingWheel_StartStop_1millionTimers_WithDifferentDurations-8 1000000 323 ns/op
BenchmarkStandardTimer_StartStop_1millionTimers_WithDifferentDurations-8 1000000 239 ns/op
BenchmarkTimingWheel_StartStop_5millionsTimers_WithSameDurations-8 5000000 608 ns/op
BenchmarkStandardTimer_StartStop_5millionsTimers_WithSameDurations-8 5000000 288 ns/op
BenchmarkTimingWheel_StartStop_5millionsTimers_WithDifferentDurations-8 5000000 330 ns/op
BenchmarkStandardTimer_StartStop_5millionsTimers_WithDifferentDurations-8 5000000 465 ns/op
BenchmarkTimingWheel_StartStop_10millionsTimers_WithSameDurations-8 10000000 502 ns/op
BenchmarkStandardTimer_StartStop_10millionsTimers_WithSameDurations-8 10000000 376 ns/op
BenchmarkTimingWheel_StartStop_10millionsTimers_WithDifferentDurations-8 10000000 344 ns/op
BenchmarkStandardTimer_StartStop_10millionsTimers_WithDifferentDurations-8 10000000 1459 ns/op
BenchmarkTimingWheel_10kTimers_StartStop-8 5000000 411 ns/op
BenchmarkStandardTimer_10kTimers_StartStop-8 5000000 581 ns/op
BenchmarkTimingWheel_100kTimers_StartStop-8 5000000 333 ns/op
BenchmarkStandardTimer_100kTimers_StartStop-8 5000000 541 ns/op
BenchmarkTimingWheel_1mTimers_StartStop-8 5000000 372 ns/op
BenchmarkStandardTimer_1mTimers_StartStop-8 2000000 1302 ns/op
BenchmarkTimingWheel_10mTimers_StartStop-8 5000000 427 ns/op
BenchmarkStandardTimer_10mTimers_StartStop-8 1000000 2180 ns/op
PASS
ok github.com/RussellLuo/timingwheel 106.640s
```
@@ -7,11 +7,20 @@ import (
"github.com/RussellLuo/timingwheel"
)
func benchmarkTimingWheel_StartStop(b *testing.B, genD func(int) time.Duration) {
func genD(i int) time.Duration {
return time.Duration(i%10000) * time.Millisecond
}
func benchmarkTimingWheel_StartStop(b *testing.B, n int) {
tw := timingwheel.NewTimingWheel(time.Millisecond, 20)
tw.Start()
defer tw.Stop()
for i := 0; i < n; i++ {
tw.AfterFunc(genD(i), func() {})
}
b.ResetTimer()
timers := make([]*timingwheel.Timer, b.N)
for i := 0; i < b.N; i++ {
timers[i] = tw.AfterFunc(genD(i), func() {})
@@ -22,7 +31,12 @@ func benchmarkTimingWheel_StartStop(b *testing.B, genD func(int) time.Duration)
}
}
func benchmarkStandardTimer_StartStop(b *testing.B, genD func(int) time.Duration) {
func benchmarkStandardTimer_StartStop(b *testing.B, n int) {
for i := 0; i < n; i++ {
time.AfterFunc(genD(i), func() {})
}
b.ResetTimer()
timers := make([]*time.Timer, b.N)
for i := 0; i < b.N; i++ {
timers[i] = time.AfterFunc(genD(i), func() {})
@@ -33,86 +47,34 @@ func benchmarkStandardTimer_StartStop(b *testing.B, genD func(int) time.Duration
}
}
func BenchmarkTimingWheel_StartStop_1millionTimers_WithSameDurations(b *testing.B) {
b.N = 1000000
benchmarkTimingWheel_StartStop(b, func(int) time.Duration {
return time.Second
})
}
func BenchmarkStandardTimer_StartStop_1millionTimers_WithSameDurations(b *testing.B) {
b.N = 1000000
benchmarkStandardTimer_StartStop(b, func(int) time.Duration {
return time.Second
})
}
func BenchmarkTimingWheel_StartStop_1millionTimers_WithDifferentDurations(b *testing.B) {
b.N = 1000000
benchmarkTimingWheel_StartStop(b, func(i int) time.Duration {
return time.Duration(i%10000) * time.Millisecond
})
}
func BenchmarkStandardTimer_StartStop_1millionTimers_WithDifferentDurations(b *testing.B) {
b.N = 1000000
benchmarkStandardTimer_StartStop(b, func(i int) time.Duration {
return time.Duration(i%10000) * time.Millisecond
})
}
func BenchmarkTimingWheel_StartStop_5millionsTimers_WithSameDurations(b *testing.B) {
b.N = 5000000
benchmarkTimingWheel_StartStop(b, func(int) time.Duration {
return time.Second
})
func BenchmarkTimingWheel_10kTimers_StartStop(b *testing.B) {
benchmarkTimingWheel_StartStop(b, 10000)
}
func BenchmarkStandardTimer_StartStop_5millionsTimers_WithSameDurations(b *testing.B) {
b.N = 5000000
benchmarkStandardTimer_StartStop(b, func(int) time.Duration {
return time.Second
})
func BenchmarkStandardTimer_10kTimers_StartStop(b *testing.B) {
benchmarkStandardTimer_StartStop(b, 10000)
}
func BenchmarkTimingWheel_StartStop_5millionsTimers_WithDifferentDurations(b *testing.B) {
b.N = 5000000
benchmarkTimingWheel_StartStop(b, func(i int) time.Duration {
return time.Duration(i%10000) * time.Millisecond
})
func BenchmarkTimingWheel_100kTimers_StartStop(b *testing.B) {
benchmarkTimingWheel_StartStop(b, 100000)
}
func BenchmarkStandardTimer_StartStop_5millionsTimers_WithDifferentDurations(b *testing.B) {
b.N = 5000000
benchmarkStandardTimer_StartStop(b, func(i int) time.Duration {
return time.Duration(i%10000) * time.Millisecond
})
func BenchmarkStandardTimer_100kTimers_StartStop(b *testing.B) {
benchmarkStandardTimer_StartStop(b, 100000)
}
func BenchmarkTimingWheel_StartStop_10millionsTimers_WithSameDurations(b *testing.B) {
b.N = 10000000
benchmarkTimingWheel_StartStop(b, func(int) time.Duration {
return time.Second
})
func BenchmarkTimingWheel_1mTimers_StartStop(b *testing.B) {
benchmarkTimingWheel_StartStop(b, 1000000)
}
func BenchmarkStandardTimer_StartStop_10millionsTimers_WithSameDurations(b *testing.B) {
b.N = 10000000
benchmarkStandardTimer_StartStop(b, func(int) time.Duration {
return time.Second
})
func BenchmarkStandardTimer_1mTimers_StartStop(b *testing.B) {
benchmarkStandardTimer_StartStop(b, 1000000)
}
func BenchmarkTimingWheel_StartStop_10millionsTimers_WithDifferentDurations(b *testing.B) {
b.N = 10000000
benchmarkTimingWheel_StartStop(b, func(i int) time.Duration {
return time.Duration(i%10000) * time.Millisecond
})
func BenchmarkTimingWheel_10mTimers_StartStop(b *testing.B) {
benchmarkTimingWheel_StartStop(b, 10000000)
}
func BenchmarkStandardTimer_StartStop_10millionsTimers_WithDifferentDurations(b *testing.B) {
b.N = 10000000
benchmarkStandardTimer_StartStop(b, func(i int) time.Duration {
return time.Duration(i%10000) * time.Millisecond
})
func BenchmarkStandardTimer_10mTimers_StartStop(b *testing.B) {
benchmarkStandardTimer_StartStop(b, 10000000)
}

0 comments on commit 52de9be

Please sign in to comment.