| 1 | package triescip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/ |
| 2 | |
| 3 | import ( |
| 4 | "crypto/randscip-go gomod github.com/golang/go/src go1.19 `crypto/rand`/" |
| 5 | "testingscip-go gomod github.com/golang/go/src go1.19 testing/" |
| 6 | ) |
| 7 | |
| 8 | var stringKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/stringKeys. [1000]string // random string keys |
| 9 | const bytesPerKeyscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/bytesPerKey. = 30 |
| 10 | |
| 11 | var pathKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/pathKeys. [1000]string // random /paths/of/parts keys |
| 12 | const partsPerKeyscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/partsPerKey. = 3 // (e.g. /a/b/c has parts /a, /b, /c) |
| 13 | const bytesPerPartscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/bytesPerPart. = 10 |
| 14 | |
| 15 | func initscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/init().() { |
| 16 | // string keys |
| 17 | for i := 0; i < len(stringKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/stringKeys.); i++ { |
| 18 | key := make([]byte, bytesPerKeyscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/bytesPerKey.) |
| 19 | if _, err := randscip-go gomod github.com/golang/go/src go1.19 `crypto/rand`/.Readscip-go gomod github.com/golang/go/src go1.19 `crypto/rand`/Read().(key); err != nil { |
| 20 | panic("error generating random byte slice") |
| 21 | } |
| 22 | stringKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/stringKeys.[i] = string(key) |
| 23 | } |
| 24 | |
| 25 | // path keys |
| 26 | for i := 0; i < len(pathKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/pathKeys.); i++ { |
| 27 | var key string |
| 28 | for j := 0; j < partsPerKeyscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/partsPerKey.; j++ { |
| 29 | key += "/" |
| 30 | part := make([]byte, bytesPerPartscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/bytesPerPart.) |
| 31 | if _, err := randscip-go gomod github.com/golang/go/src go1.19 `crypto/rand`/.Readscip-go gomod github.com/golang/go/src go1.19 `crypto/rand`/Read().(part); err != nil { |
| 32 | panic("error generating random byte slice") |
| 33 | } |
| 34 | key += string(part) |
| 35 | } |
| 36 | pathKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/pathKeys.[i] = key |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | // RuneTrie |
| 41 | /////////////////////////////////////////////////////////////////////////////// |
| 42 | |
| 43 | // string keys |
| 44 | |
| 45 | func BenchmarkRuneTriePutStringKeyscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/BenchmarkRuneTriePutStringKey().(b *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Bscip-go gomod github.com/golang/go/src go1.19 testing/B#) { |
| 46 | trie := NewRuneTriescip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/NewRuneTrie().() |
| 47 | b.ResetTimerscip-go gomod github.com/golang/go/src go1.19 testing/B#ResetTimer().() |
| 48 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.19 testing/B#ReportAllocs().() |
| 49 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.19 testing/B#N.; i++ { |
| 50 | trie.Putscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/RuneTrie#Put().(stringKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/stringKeys.[i%len(stringKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/stringKeys.)], i) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | func BenchmarkRuneTrieGetStringKeyscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/BenchmarkRuneTrieGetStringKey().(b *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Bscip-go gomod github.com/golang/go/src go1.19 testing/B#) { |
| 55 | trie := NewRuneTriescip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/NewRuneTrie().() |
| 56 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.19 testing/B#N.; i++ { |
| 57 | trie.Putscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/RuneTrie#Put().(stringKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/stringKeys.[i%len(stringKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/stringKeys.)], i) |
| 58 | } |
| 59 | b.ResetTimerscip-go gomod github.com/golang/go/src go1.19 testing/B#ResetTimer().() |
| 60 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.19 testing/B#ReportAllocs().() |
| 61 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.19 testing/B#N.; i++ { |
| 62 | trie.Getscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/RuneTrie#Get().(stringKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/stringKeys.[i%len(stringKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/stringKeys.)]) |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | // path keys |
| 67 | |
| 68 | func BenchmarkRuneTriePutPathKeyscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/BenchmarkRuneTriePutPathKey().(b *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Bscip-go gomod github.com/golang/go/src go1.19 testing/B#) { |
| 69 | trie := NewRuneTriescip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/NewRuneTrie().() |
| 70 | b.ResetTimerscip-go gomod github.com/golang/go/src go1.19 testing/B#ResetTimer().() |
| 71 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.19 testing/B#ReportAllocs().() |
| 72 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.19 testing/B#N.; i++ { |
| 73 | trie.Putscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/RuneTrie#Put().(pathKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/pathKeys.[i%len(pathKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/pathKeys.)], i) |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | func BenchmarkRuneTrieGetPathKeyscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/BenchmarkRuneTrieGetPathKey().(b *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Bscip-go gomod github.com/golang/go/src go1.19 testing/B#) { |
| 78 | trie := NewRuneTriescip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/NewRuneTrie().() |
| 79 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.19 testing/B#N.; i++ { |
| 80 | trie.Putscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/RuneTrie#Put().(pathKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/pathKeys.[i%len(pathKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/pathKeys.)], i) |
| 81 | } |
| 82 | b.ResetTimerscip-go gomod github.com/golang/go/src go1.19 testing/B#ResetTimer().() |
| 83 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.19 testing/B#ReportAllocs().() |
| 84 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.19 testing/B#N.; i++ { |
| 85 | trie.Getscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/RuneTrie#Get().(pathKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/pathKeys.[i%len(pathKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/pathKeys.)]) |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | // PathTrie |
| 90 | /////////////////////////////////////////////////////////////////////////////// |
| 91 | |
| 92 | // string keys |
| 93 | |
| 94 | func BenchmarkPathTriePutStringKeyscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/BenchmarkPathTriePutStringKey().(b *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Bscip-go gomod github.com/golang/go/src go1.19 testing/B#) { |
| 95 | trie := NewPathTriescip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/NewPathTrie().() |
| 96 | b.ResetTimerscip-go gomod github.com/golang/go/src go1.19 testing/B#ResetTimer().() |
| 97 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.19 testing/B#ReportAllocs().() |
| 98 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.19 testing/B#N.; i++ { |
| 99 | trie.Putscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/PathTrie#Put().(stringKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/stringKeys.[i%len(stringKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/stringKeys.)], i) |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | func BenchmarkPathTrieGetStringKeyscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/BenchmarkPathTrieGetStringKey().(b *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Bscip-go gomod github.com/golang/go/src go1.19 testing/B#) { |
| 104 | trie := NewPathTriescip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/NewPathTrie().() |
| 105 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.19 testing/B#N.; i++ { |
| 106 | trie.Putscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/PathTrie#Put().(stringKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/stringKeys.[i%len(stringKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/stringKeys.)], i) |
| 107 | } |
| 108 | b.ResetTimerscip-go gomod github.com/golang/go/src go1.19 testing/B#ResetTimer().() |
| 109 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.19 testing/B#ReportAllocs().() |
| 110 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.19 testing/B#N.; i++ { |
| 111 | trie.Getscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/PathTrie#Get().(stringKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/stringKeys.[i%len(stringKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/stringKeys.)]) |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | // path keys |
| 116 | |
| 117 | func BenchmarkPathTriePutPathKeyscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/BenchmarkPathTriePutPathKey().(b *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Bscip-go gomod github.com/golang/go/src go1.19 testing/B#) { |
| 118 | trie := NewPathTriescip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/NewPathTrie().() |
| 119 | b.ResetTimerscip-go gomod github.com/golang/go/src go1.19 testing/B#ResetTimer().() |
| 120 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.19 testing/B#ReportAllocs().() |
| 121 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.19 testing/B#N.; i++ { |
| 122 | trie.Putscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/PathTrie#Put().(pathKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/pathKeys.[i%len(pathKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/pathKeys.)], i) |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | func BenchmarkPathTrieGetPathKeyscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/BenchmarkPathTrieGetPathKey().(b *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Bscip-go gomod github.com/golang/go/src go1.19 testing/B#) { |
| 127 | trie := NewPathTriescip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/NewPathTrie().() |
| 128 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.19 testing/B#N.; i++ { |
| 129 | trie.Putscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/PathTrie#Put().(pathKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/pathKeys.[i%len(pathKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/pathKeys.)], i) |
| 130 | } |
| 131 | b.ResetTimerscip-go gomod github.com/golang/go/src go1.19 testing/B#ResetTimer().() |
| 132 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.19 testing/B#ReportAllocs().() |
| 133 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.19 testing/B#N.; i++ { |
| 134 | trie.Getscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/PathTrie#Get().(pathKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/pathKeys.[i%len(pathKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/pathKeys.)]) |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | // benchmark PathSegmenter |
| 139 | |
| 140 | func BenchmarkPathSegmenterscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/BenchmarkPathSegmenter().(b *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Bscip-go gomod github.com/golang/go/src go1.19 testing/B#) { |
| 141 | b.ResetTimerscip-go gomod github.com/golang/go/src go1.19 testing/B#ResetTimer().() |
| 142 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.19 testing/B#ReportAllocs().() |
| 143 | for j := 0; j < b.Nscip-go gomod github.com/golang/go/src go1.19 testing/B#N.; j++ { |
| 144 | for part, i := PathSegmenterscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/PathSegmenter().(pathKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/pathKeys.[j%len(pathKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/pathKeys.)], 0); ; part, i = PathSegmenterscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/PathSegmenter().(pathKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/pathKeys.[j%len(pathKeysscip-go gomod github.com/dghubble/trie . `github.com/dghubble/trie`/pathKeys.)], i) { |
| 145 | var _ = part // NoOp 'use' the key part |
| 146 | if i == -1 { |
| 147 | break |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | } |