-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcompress_test.go
57 lines (44 loc) · 918 Bytes
/
compress_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
package libdeflate
import (
"bytes"
"compress/zlib"
"io"
"testing"
)
/*---------------------
UNIT TESTS
-----------------------*/
func TestCompressZlibConvenience(t *testing.T) {
_, comp, err := CompressZlib(shortString, nil)
if err != nil {
t.Error(err)
}
b := bytes.NewBuffer(comp)
r, err := zlib.NewReader(b)
if err != nil {
t.Error(err)
}
defer r.Close()
dc := &bytes.Buffer{}
io.Copy(dc, r)
slicesEqual(shortString, dc.Bytes(), t)
}
/*---------------------
BENCHMARKS
-----------------------*/
func BenchmarkCompressZlib(b *testing.B) {
out := make([]byte, len(shortString))
b.ResetTimer()
for i := 0; i < b.N; i++ {
CompressZlib(shortString, out)
}
}
func BenchmarkCompressor_CompressZlib(b *testing.B) {
c, _ := NewCompressor()
defer c.Close()
out := make([]byte, len(shortString))
b.ResetTimer()
for i := 0; i < b.N; i++ {
c.CompressZlib(shortString, out)
}
}