tendermint/libs/clist/bench_test.go
Dev Ojha 89668c3179 clist: Speedup functions (#2208)
* clist: Speedup detachNext() and detachPrev()

We used unnecessary function calls, defers, and extra mutexes.
These are not our friends for writing fast code in our libs.

* Remove more defers from clist functions

* Add more benchmarks
2018-08-14 19:00:21 +04:00

47 lines
771 B
Go

package clist
import "testing"
func BenchmarkDetaching(b *testing.B) {
lst := New()
for i := 0; i < b.N+1; i++ {
lst.PushBack(i)
}
start := lst.Front()
nxt := start.Next()
b.ResetTimer()
for i := 0; i < b.N; i++ {
start.removed = true
start.DetachNext()
start.DetachPrev()
tmp := nxt
nxt = nxt.Next()
start = tmp
}
}
// This is used to benchmark the time of RMutex.
func BenchmarkRemoved(b *testing.B) {
lst := New()
for i := 0; i < b.N+1; i++ {
lst.PushBack(i)
}
start := lst.Front()
nxt := start.Next()
b.ResetTimer()
for i := 0; i < b.N; i++ {
start.Removed()
tmp := nxt
nxt = nxt.Next()
start = tmp
}
}
func BenchmarkPushBack(b *testing.B) {
lst := New()
b.ResetTimer()
for i := 0; i < b.N; i++ {
lst.PushBack(i)
}
}