-
Notifications
You must be signed in to change notification settings - Fork 84
/
benchmarks_srw_test.go
74 lines (69 loc) · 1.51 KB
/
benchmarks_srw_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
package mp4
import (
"bytes"
"os"
"testing"
"github.com/Eyevinn/mp4ff/bits"
)
func TestDecodEncodeFileSRW(t *testing.T) {
testFiles := []string{
"1.m4s",
"prog_8s.mp4",
}
for _, testFile := range testFiles {
raw, err := os.ReadFile("testdata/" + testFile)
if err != nil {
t.Error(err)
}
rawOut := make([]byte, len(raw))
t.Run(testFile, func(t *testing.T) {
sr := bits.NewFixedSliceReader(raw)
f, err := DecodeFileSR(sr)
if err != nil {
t.Error(err)
}
sw := bits.NewFixedSliceWriterFromSlice(rawOut)
f.FragEncMode = EncModeBoxTree
err = f.EncodeSW(sw)
if err != nil {
t.Error(err)
}
if !bytes.Equal(raw, sw.Bytes()) {
t.Errorf("%s: generated bytes differ from input", testFile)
}
})
}
}
func BenchmarkDecodeFileSR(b *testing.B) {
testFiles := []string{
"1.m4s",
"prog_8s.mp4",
}
for _, testFile := range testFiles {
raw, _ := os.ReadFile("testdata/" + testFile)
b.Run(testFile, func(b *testing.B) {
for i := 0; i < b.N; i++ {
sr := bits.NewFixedSliceReader(raw)
_, _ = DecodeFileSR(sr)
}
})
}
}
func BenchmarkEncodeFileSW(b *testing.B) {
testFiles := []string{
"1.m4s",
"prog_8s.mp4",
}
for _, testFile := range testFiles {
raw, _ := os.ReadFile("testdata/" + testFile)
inBuf := bytes.NewBuffer(raw)
decFile, _ := DecodeFile(inBuf)
rawOut := make([]byte, len(raw))
b.Run(testFile, func(b *testing.B) {
for i := 0; i < b.N; i++ {
sw := bits.NewFixedSliceWriterFromSlice(rawOut)
_ = decFile.EncodeSW(sw)
}
})
}
}