(b *testing.B)
| 89 | const benchmarkDataSize = 10000000 |
| 90 | |
| 91 | func 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 | |
| 137 | func compressionBenchmark(b *testing.B, comp Compressor, input []byte, output *bytes.Buffer) { |
| 138 | b.Helper() |
nothing calls this directly
no test coverage detected