-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasync_reader_test.go
More file actions
55 lines (45 loc) · 938 Bytes
/
async_reader_test.go
File metadata and controls
55 lines (45 loc) · 938 Bytes
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
package extio
import (
"bytes"
"crypto/rand"
"io"
"io/ioutil"
mr "math/rand"
"testing"
)
func TestAsyncReader(t *testing.T) {
for i := 0; i < 200; i++ {
buf := make([]byte, 2<<10+mr.Intn(32<<10))
rand.Read(buf)
ar := NewAsyncReader(bytes.NewReader(buf))
ar.BufferSize = mr.Intn(64 << 10)
ar.ChannelSize = mr.Intn(128)
ar.Start()
data, err := ioutil.ReadAll(ar)
if err != nil {
t.Error(err)
}
if !bytes.Equal(buf, data) {
t.Error("buf/data mismatch")
}
}
}
func BenchmarkReader(b *testing.B) {
buf := make([]byte, 8<<20)
b.SetBytes(int64(len(buf)))
b.ResetTimer()
for i := 0; i < b.N; i++ {
r := bytes.NewReader(buf)
io.Copy(ioutil.Discard, r)
}
}
func BenchmarkAsyncReader(b *testing.B) {
buf := make([]byte, 8<<20)
b.SetBytes(int64(len(buf)))
b.ResetTimer()
for i := 0; i < b.N; i++ {
ar := NewAsyncReader(bytes.NewReader(buf))
ar.Start()
io.Copy(ioutil.Discard, ar)
}
}