| 85 | } |
| 86 | |
| 87 | func BenchmarkCompress(b *testing.B) { |
| 88 | data := []byte(strings.Repeat("123456789", 1024)) |
| 89 | |
| 90 | testCases := []struct { |
| 91 | name string |
| 92 | }{ |
| 93 | { |
| 94 | name: snappy.Name, |
| 95 | }, |
| 96 | { |
| 97 | name: snappyblock.Name, |
| 98 | }, |
| 99 | { |
| 100 | name: zstd.Name, |
| 101 | }, |
| 102 | } |
| 103 | |
| 104 | for _, tc := range testCases { |
| 105 | b.Run(tc.name, func(b *testing.B) { |
| 106 | c := encoding.GetCompressor(tc.name) |
| 107 | for b.Loop() { |
| 108 | w, _ := c.Compress(io.Discard) |
| 109 | _, _ = w.Write(data) |
| 110 | _ = w.Close() |
| 111 | } |
| 112 | b.ReportAllocs() |
| 113 | }) |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | func BenchmarkDecompress(b *testing.B) { |
| 118 | data := []byte(strings.Repeat("123456789", 1024)) |