github.com/ledgerwatch/erigon-lib@v1.0.0/compress/decompress_bench_test.go (about) 1 /* 2 Copyright 2021 Erigon contributors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package compress 18 19 import ( 20 "fmt" 21 "os" 22 "testing" 23 24 "github.com/stretchr/testify/require" 25 ) 26 27 func BenchmarkDecompressNext(b *testing.B) { 28 t := new(testing.T) 29 d := prepareDict(t) 30 defer d.Close() 31 g := d.MakeGetter() 32 for i := 0; i < b.N; i++ { 33 _, _ = g.Next(nil) 34 if !g.HasNext() { 35 g.Reset(0) 36 } 37 } 38 } 39 40 func BenchmarkDecompressFastNext(b *testing.B) { 41 t := new(testing.T) 42 d := prepareDict(t) 43 defer d.Close() 44 g := d.MakeGetter() 45 buf := make([]byte, 100) 46 for i := 0; i < b.N; i++ { 47 _, _ = g.FastNext(buf) 48 if !g.HasNext() { 49 g.Reset(0) 50 } 51 } 52 } 53 54 func BenchmarkDecompressSkip(b *testing.B) { 55 t := new(testing.T) 56 d := prepareDict(t) 57 defer d.Close() 58 g := d.MakeGetter() 59 60 for i := 0; i < b.N; i++ { 61 _, _ = g.Skip() 62 if !g.HasNext() { 63 g.Reset(0) 64 } 65 } 66 } 67 68 func BenchmarkDecompressMatch(b *testing.B) { 69 t := new(testing.T) 70 d := prepareDict(t) 71 defer d.Close() 72 g := d.MakeGetter() 73 for i := 0; i < b.N; i++ { 74 _, _ = g.Match([]byte("longlongword")) 75 } 76 } 77 78 func BenchmarkDecompressMatchCmp(b *testing.B) { 79 t := new(testing.T) 80 d := prepareDict(t) 81 defer d.Close() 82 g := d.MakeGetter() 83 for i := 0; i < b.N; i++ { 84 _ = g.MatchCmp([]byte("longlongword")) 85 if !g.HasNext() { 86 g.Reset(0) 87 } 88 } 89 } 90 91 func BenchmarkDecompressMatchPrefix(b *testing.B) { 92 t := new(testing.T) 93 d := prepareDict(t) 94 defer d.Close() 95 g := d.MakeGetter() 96 97 for i := 0; i < b.N; i++ { 98 _ = g.MatchPrefix([]byte("longlongword")) 99 } 100 } 101 102 func BenchmarkDecompressMatchPrefixCmp(b *testing.B) { 103 t := new(testing.T) 104 d := prepareDict(t) 105 defer d.Close() 106 g := d.MakeGetter() 107 108 for i := 0; i < b.N; i++ { 109 _ = g.MatchPrefixCmp([]byte("longlongword")) 110 } 111 } 112 113 func BenchmarkDecompressTorrent(t *testing.B) { 114 t.Skip() 115 116 //fpath := "/Volumes/wotah/mainnet/snapshots/v1-013500-014000-bodies.seg" 117 fpath := "/Volumes/wotah/mainnet/snapshots/v1-013500-014000-transactions.seg" 118 //fpath := "./v1-006000-006500-transactions.seg" 119 st, err := os.Stat(fpath) 120 require.NoError(t, err) 121 fmt.Printf("file: %v, size: %d\n", st.Name(), st.Size()) 122 123 condensePatternTableBitThreshold = 5 124 fmt.Printf("bit threshold: %d\n", condensePatternTableBitThreshold) 125 126 t.Run("init", func(t *testing.B) { 127 for i := 0; i < t.N; i++ { 128 d, err := NewDecompressor(fpath) 129 require.NoError(t, err) 130 d.Close() 131 } 132 }) 133 t.Run("run", func(t *testing.B) { 134 d, err := NewDecompressor(fpath) 135 require.NoError(t, err) 136 defer d.Close() 137 138 getter := d.MakeGetter() 139 140 for i := 0; i < t.N && getter.HasNext(); i++ { 141 _, sz := getter.Next(nil) 142 if sz == 0 { 143 t.Fatal("sz == 0") 144 } 145 } 146 }) 147 }