| 1 |
package zstd |
| 2 |
|
| 3 |
import "testing" |
| 4 |
|
| 5 |
// predefinedFSEInputs returns the three RFC default distributions |
| 6 |
// (litLength, offset, matchLength) as fseDecoders, ready for buildDtable. |
| 7 |
// Defined without build constraints so the benchmark can run under both the |
| 8 |
// asm and -tags noasm (pure-Go) builds for an apples-to-apples comparison. |
| 9 |
func predefinedFSEInputs() map[string]func() *fseDecoder { |
| 10 |
return map[string]func() *fseDecoder{ |
| 11 |
"litLength": func() *fseDecoder { |
| 12 |
s := &fseDecoder{actualTableLog: 6, symbolLen: 36} |
| 13 |
copy(s.norm[:], []int16{4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, |
| 14 |
2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 1, 1, 1, 1, 1, |
| 15 |
-1, -1, -1, -1}) |
| 16 |
return s |
| 17 |
}, |
| 18 |
"offset": func() *fseDecoder { |
| 19 |
s := &fseDecoder{actualTableLog: 5, symbolLen: 29} |
| 20 |
copy(s.norm[:], []int16{ |
| 21 |
1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, |
| 22 |
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1}) |
| 23 |
return s |
| 24 |
}, |
| 25 |
"matchLength": func() *fseDecoder { |
| 26 |
s := &fseDecoder{actualTableLog: 6, symbolLen: 53} |
| 27 |
copy(s.norm[:], []int16{ |
| 28 |
1, 4, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, |
| 29 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 30 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, |
| 31 |
-1, -1, -1, -1, -1}) |
| 32 |
return s |
| 33 |
}, |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
func BenchmarkBuildDtable(b *testing.B) { |
| 38 |
for name, mk := range predefinedFSEInputs() { |
| 39 |
b.Run(name, func(b *testing.B) { |
| 40 |
s := mk() |
| 41 |
b.ReportAllocs() |
| 42 |
b.ResetTimer() |
| 43 |
for i := 0; i < b.N; i++ { |
| 44 |
// Reset the mutated parts so each iteration does real work. |
| 45 |
for j := range s.dt { |
| 46 |
s.dt[j] = 0 |
| 47 |
} |
| 48 |
for j := range s.stateTable { |
| 49 |
s.stateTable[j] = 0 |
| 50 |
} |
| 51 |
if err := s.buildDtable(); err != nil { |
| 52 |
b.Fatal(err) |
| 53 |
} |
| 54 |
} |
| 55 |
}) |
| 56 |
} |
| 57 |
} |