-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriter_test.go
59 lines (54 loc) · 1.23 KB
/
writer_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
package pzip
import (
"reflect"
"testing"
)
func TestHeaderPrepare(t *testing.T) {
for i := 0; i < 1000; i++ {
h := &header{
FileHeader: &FileHeader{
CompressedSize64: uint64(i),
UncompressedSize64: uint64(i),
},
offset: uint32max + uint64(i),
}
h1 := &header{
FileHeader: &FileHeader{
CompressedSize64: uint64(i),
UncompressedSize64: uint64(i),
},
offset: uint32max + uint64(i),
}
headerPrepareByAppend(h)
headerPrepareByWriteBuf(h1)
if !reflect.DeepEqual(h, h1) {
t.Errorf("header prepare fail: got %v, want %v", h, h1)
}
}
}
func BenchmarkHeaderPrepare(b *testing.B) {
b.Run("HeaderPrepareByAppend", func(b *testing.B) {
for i := 0; i < b.N; i++ {
h := &header{
FileHeader: &FileHeader{
CompressedSize64: uint32max + uint64(i),
UncompressedSize64: uint32max + uint64(i),
},
offset: uint32max + uint64(i),
}
headerPrepareByAppend(h)
}
})
b.Run("HeaderPrepareByWriteBuf", func(b *testing.B) {
for i := 0; i < b.N; i++ {
h := &header{
FileHeader: &FileHeader{
CompressedSize64: uint32max + uint64(i),
UncompressedSize64: uint32max + uint64(i),
},
offset: uint32max + uint64(i),
}
headerPrepareByWriteBuf(h)
}
})
}