forked from tehsphinx/concurrent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bytes_test.go
87 lines (75 loc) · 1.27 KB
/
bytes_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package concurrent
import (
"sync"
"testing"
"time"
)
func TestBytes(t *testing.T) {
s := NewBytes()
alphabet := []byte("abcdefghijklmnopqrstuvwxyz")
settovar := []byte("zzzzzzzzzz")
for i := 0; i < 10; i++ {
go func() {
for {
s.Get()
}
}()
}
for j := 1; j < len(alphabet); j++ {
go func(alphabetsl []byte) {
for {
s.Set(alphabetsl)
}
}(alphabet[:j])
}
for i := 0; i < len(settovar); i++ {
go func(ab []byte) {
for {
s.Append(ab)
}
}(settovar[:i])
}
time.Sleep(5 * time.Second)
}
func BenchmarkBytes_Set(b *testing.B) {
s := NewBytes()
wg := &sync.WaitGroup{}
wg.Add(10)
for i := 0; i < 10; i++ {
go func(wg *sync.WaitGroup) {
for i := 0; i < b.N/10; i++ {
s.Set([]byte("zz"))
}
wg.Done()
}(wg)
}
wg.Wait()
}
func BenchmarkBytes_Get(b *testing.B) {
s := NewBytes()
wg := &sync.WaitGroup{}
wg.Add(10)
for i := 0; i < 10; i++ {
go func(wg *sync.WaitGroup) {
for i := 0; i < b.N/10; i++ {
s.Get()
}
wg.Done()
}(wg)
}
wg.Wait()
}
func BenchmarkBytes_Append(b *testing.B) {
s := NewBytes()
wg := &sync.WaitGroup{}
wg.Add(10)
for i := 0; i < 10; i++ {
go func(wg *sync.WaitGroup) {
for i := 0; i < b.N/10; i++ {
s.Append([]byte("abc"))
}
wg.Done()
}(wg)
}
wg.Wait()
}