1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/pkg/collections/orderedintset_test.go
Alexandr Morozov 5128feb690 Refactoring collections/orderedintset and benchmarks for it
Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)
2014-05-14 06:04:12 +04:00

71 lines
1.2 KiB
Go

package collections
import (
"math/rand"
"testing"
)
func BenchmarkPush(b *testing.B) {
var testSet []int
for i := 0; i < 1000; i++ {
testSet = append(testSet, rand.Int())
}
s := NewOrderedIntSet()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, elem := range testSet {
s.Push(elem)
}
}
}
func BenchmarkPop(b *testing.B) {
var testSet []int
for i := 0; i < 1000; i++ {
testSet = append(testSet, rand.Int())
}
s := NewOrderedIntSet()
for _, elem := range testSet {
s.Push(elem)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for j := 0; j < 1000; j++ {
s.Pop()
}
}
}
func BenchmarkExist(b *testing.B) {
var testSet []int
for i := 0; i < 1000; i++ {
testSet = append(testSet, rand.Intn(2000))
}
s := NewOrderedIntSet()
for _, elem := range testSet {
s.Push(elem)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for j := 0; j < 1000; j++ {
s.Exists(j)
}
}
}
func BenchmarkRemove(b *testing.B) {
var testSet []int
for i := 0; i < 1000; i++ {
testSet = append(testSet, rand.Intn(2000))
}
s := NewOrderedIntSet()
for _, elem := range testSet {
s.Push(elem)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for j := 0; j < 1000; j++ {
s.Remove(j)
}
}
}