-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_test.go
65 lines (55 loc) · 1.34 KB
/
list_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2012 by Christoph Hack <[email protected]>
// All rights reserved. Distributed under the Simplified BSD License.
// TODO(tux21b): write proper test cases and benchmarks
package goco
import (
"sync"
"testing"
)
func TestList(t *testing.T) {
list := &List{}
list.Add("foo")
list.Add("bar")
list.Add("hah")
list.Add("foo")
list.Remove("foo")
list.Add("foo")
list.Remove("bar")
}
func BenchmarkList(b *testing.B) {
list := &List{}
wg := &sync.WaitGroup{}
inserter := func(values ...string) {
for i := 0; i < b.N; i++ {
for _, v := range values {
list.Add(v)
}
}
wg.Done()
}
getter := func(values ...string) {
for i := 0; i < b.N; i++ {
for _, v := range values {
list.Contains(v)
}
}
wg.Done()
}
remover := func(values ...string) {
for i := 0; i < b.N; i++ {
for _, v := range values {
list.Remove(v)
}
}
wg.Done()
}
wg.Add(7)
go inserter("foo", "bar", "blub", "bla")
go inserter("blub")
go remover("foo", "bla", "quak")
go getter("foo", "bar", "boo")
go getter("foo", "quak")
go getter("foo", "bar", "boo")
go getter("foo", "quak")
wg.Wait()
}