MCPcopy
hub / github.com/kopia/kopia / BenchmarkCompressor

Function BenchmarkCompressor

repo/compression/compressor_test.go:91–135  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

89const benchmarkDataSize = 10000000
90
91func BenchmarkCompressor(b *testing.B) {
92 compressibleData := bytes.Repeat([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, benchmarkDataSize/10)
93 zeroData := make([]byte, benchmarkDataSize)
94
95 rndData := make([]byte, benchmarkDataSize)
96 rand.Read(rndData)
97
98 var cData, dData bytes.Buffer
99
100 var sortedNames []Name
101 for id := range ByName {
102 if !IsSupported(id) {
103 continue
104 }
105
106 sortedNames = append(sortedNames, id)
107 }
108
109 slices.Sort(sortedNames)
110
111 for _, id := range sortedNames {
112 comp := ByName[id]
113
114 b.Run(fmt.Sprintf("%v-compress-zeroes", id), func(b *testing.B) {
115 compressionBenchmark(b, comp, zeroData, &cData)
116 })
117 b.Run(fmt.Sprintf("%v-decompress-zeroes", id), func(b *testing.B) {
118 decompressionBenchmark(b, comp, cData.Bytes(), &dData)
119 })
120
121 b.Run(fmt.Sprintf("%v-compress-compressible", id), func(b *testing.B) {
122 compressionBenchmark(b, comp, compressibleData, &cData)
123 })
124 b.Run(fmt.Sprintf("%v-decompress-compressible", id), func(b *testing.B) {
125 decompressionBenchmark(b, comp, cData.Bytes(), &dData)
126 })
127
128 b.Run(fmt.Sprintf("%v-compress-random", id), func(b *testing.B) {
129 compressionBenchmark(b, comp, rndData, &cData)
130 })
131 b.Run(fmt.Sprintf("%v-decompress-random", id), func(b *testing.B) {
132 decompressionBenchmark(b, comp, cData.Bytes(), &dData)
133 })
134 }
135}
136
137func compressionBenchmark(b *testing.B, comp Compressor, input []byte, output *bytes.Buffer) {
138 b.Helper()

Callers

nothing calls this directly

Calls 7

IsSupportedFunction · 0.85
compressionBenchmarkFunction · 0.85
decompressionBenchmarkFunction · 0.85
RepeatMethod · 0.80
RunMethod · 0.65
ReadMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected