(b *testing.B, testfile, level, n int)
| 150 | } |
| 151 | |
| 152 | func benchmarkEncoder(b *testing.B, testfile, level, n int) { |
| 153 | b.SetBytes(int64(n)) |
| 154 | buf0, err := os.ReadFile(testfiles[testfile]) |
| 155 | if err != nil { |
| 156 | b.Fatal(err) |
| 157 | } |
| 158 | if len(buf0) == 0 { |
| 159 | b.Fatalf("test file %q has no data", testfiles[testfile]) |
| 160 | } |
| 161 | buf1 := make([]byte, n) |
| 162 | for i := 0; i < n; i += len(buf0) { |
| 163 | if len(buf0) > n-i { |
| 164 | buf0 = buf0[:n-i] |
| 165 | } |
| 166 | copy(buf1[i:], buf0) |
| 167 | } |
| 168 | buf0 = nil |
| 169 | runtime.GC() |
| 170 | w, err := NewWriter(io.Discard, level) |
| 171 | if err != nil { |
| 172 | b.Fatal(err) |
| 173 | } |
| 174 | b.ResetTimer() |
| 175 | b.ReportAllocs() |
| 176 | for i := 0; i < b.N; i++ { |
| 177 | w.Reset(io.Discard) |
| 178 | _, err = w.Write(buf1) |
| 179 | if err != nil { |
| 180 | b.Fatal(err) |
| 181 | } |
| 182 | err = w.Close() |
| 183 | if err != nil { |
| 184 | b.Fatal(err) |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | func BenchmarkEncodeDigitsConstant1e4(b *testing.B) { benchmarkEncoder(b, digits, constant, 1e4) } |
| 190 | func BenchmarkEncodeDigitsConstant1e5(b *testing.B) { benchmarkEncoder(b, digits, constant, 1e5) } |
no test coverage detected
searching dependent graphs…