Repository navigation
Expand file tree
/
Copy pathcompression_test.go
More file actions
97 lines (89 loc) · 2.21 KB
/
Copy pathcompression_test.go
File metadata and controls
97 lines (89 loc) · 2.21 KB
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
88
89
90
91
92
93
94
95
96
97
package logring
import (
dzstd "github.com/DataDog/zstd"
"github.com/klauspost/compress/s2"
"github.com/klauspost/compress/snappy"
"github.com/klauspost/compress/zstd"
"github.com/stretchr/testify/require"
"io"
"math/rand"
"testing"
)
type rndGen struct {
r *rand.Rand
}
func (r *rndGen) Read(b []byte) (n int, err error) {
return r.r.Read(b)
}
func newRND() *rndGen {
return &rndGen{r: rand.New(rand.NewSource(0))}
}
var compDisplayed = map[string]bool{}
func fmtPrintOnce(b *testing.B, format string, args ...interface{}) {
if _, ok := compDisplayed[b.Name()]; !ok {
b.Logf(format, args...)
compDisplayed[b.Name()] = true
}
}
func BenchmarkZSTDDatadog(b *testing.B) {
r := logData()
wr := NewCountingDiscardWriter()
w := dzstd.NewWriter(wr)
w.Write(r)
w.Close()
w = dzstd.NewWriter(wr)
b.ResetTimer()
b.ReportMetric(float64(len(r))/float64(wr.ctr), "compression")
for i := 0; i < b.N; i++ {
w.Write(r)
}
w.Close()
b.ReportMetric((float64(b.N) * float64(len(r)) / b.Elapsed().Seconds() / 1024 / 1024), "MB/sec")
}
func BenchmarkZSTD(b *testing.B) {
r := logData()
wr := NewCountingDiscardWriter()
w, err := zstd.NewWriter(wr)
require.NoError(b, err)
w.Write(r)
w.Close()
w.Reset(io.Discard)
b.ResetTimer()
b.ReportMetric(float64(len(r))/float64(wr.ctr), "compression")
for i := 0; i < b.N; i++ {
w.Write(r)
}
w.Close()
b.ReportMetric((float64(b.N) * float64(len(r)) / b.Elapsed().Seconds() / 1024 / 1024), "MB/sec")
}
func BenchmarkSnappy(b *testing.B) {
r := logData()
wr := NewCountingDiscardWriter()
w := snappy.NewBufferedWriter(wr)
w.Write(r)
w.Close()
w.Reset(io.Discard)
b.ResetTimer()
b.ReportMetric(float64(len(r))/float64(wr.ctr), "compression")
for i := 0; i < b.N; i++ {
w.Write(r)
}
w.Close()
b.ReportMetric((float64(b.N) * float64(len(r)) / b.Elapsed().Seconds() / 1024 / 1024), "MB/sec")
}
func BenchmarkS2(b *testing.B) {
r := logData()
wr := NewCountingDiscardWriter()
w := s2.NewWriter(wr)
b.Elapsed()
w.Write(r)
w.Close()
w.Reset(io.Discard)
b.ResetTimer()
b.ReportMetric(float64(len(r))/float64(wr.ctr), "compression")
for i := 0; i < b.N; i++ {
w.Write(r)
}
w.Close()
b.ReportMetric(float64(b.N)*float64(len(r))/b.Elapsed().Seconds()/1024/1024, "MB/sec")
}