fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

Benchmark compressedPostingIterator

This will set a baseline for comparing future improvements against.

BenchmarkCompressedPostingIterator/100_50-8 2000000 878 ns/op 450.86 MB/s
BenchmarkCompressedPostingIterator/10000_100-8 20000 64572 ns/op 446.30 MB/s
BenchmarkCompressedPostingIterator/10000_1000-8 20000 76463 ns/op 388.13 MB/s
BenchmarkCompressedPostingIterator/10000_10000-8 20000 82682 ns/op 359.22 MB/s
BenchmarkCompressedPostingIterator/100000_100-8 2000 885923 ns/op 292.45 MB/s
BenchmarkCompressedPostingIterator/100000_1000-8 2000 922484 ns/op 290.39 MB/s
BenchmarkCompressedPostingIterator/100000_10000-8 2000 1028873 ns/op 260.51 MB/s
BenchmarkCompressedPostingIterator/100000_100000-8 2000 1095734 ns/op 244.62 MB/s

Change-Id: Ib243d8b0e9499f62ca1423e83b526ebaa77739e1

+54
+54
hititer_test.go
··· 15 15 package zoekt 16 16 17 17 import ( 18 + "fmt" 19 + "math/rand" 18 20 "reflect" 19 21 "sort" 20 22 "testing" ··· 55 57 } 56 58 return nums 57 59 } 60 + 61 + func BenchmarkCompressedPostingIterator(b *testing.B) { 62 + cases := []struct{ size, limitSize int }{ 63 + {100, 50}, 64 + {10000, 100}, 65 + {10000, 1000}, 66 + {10000, 10000}, 67 + {100000, 100}, 68 + {100000, 1000}, 69 + {100000, 10000}, 70 + {100000, 100000}, 71 + } 72 + for _, tt := range cases { 73 + b.Run(fmt.Sprintf("%d_%d", tt.size, tt.limitSize), func(b *testing.B) { 74 + benchmarkCompressedPostingIterator(b, tt.size, tt.limitSize) 75 + }) 76 + } 77 + } 78 + 79 + func benchmarkCompressedPostingIterator(b *testing.B, size, limitsSize int) { 80 + nums := genUints32(size) 81 + limits := genUints32(limitsSize) 82 + 83 + nums = sortedUnique(nums) 84 + sort.Slice(limits, func(i, j int) bool { return limits[i] < limits[j] }) 85 + 86 + ng := stringToNGram("abc") 87 + deltas := toDeltas(nums) 88 + 89 + b.ResetTimer() 90 + 91 + for n := 0; n < b.N; n++ { 92 + it := newCompressedPostingIterator(deltas, ng) 93 + for _, limit := range limits { 94 + it.next(limit) 95 + _ = it.first() 96 + } 97 + var s Stats 98 + it.updateStats(&s) 99 + b.SetBytes(s.IndexBytesLoaded) 100 + } 101 + } 102 + 103 + func genUints32(size int) []uint32 { 104 + // Deterministic for benchmarks 105 + r := rand.New(rand.NewSource(int64(size))) 106 + nums := make([]uint32, size) 107 + for i := range nums { 108 + nums[i] = r.Uint32() 109 + } 110 + return nums 111 + }