| 22 | static constexpr uint32_t BITS = 32; |
| 23 | |
| 24 | uint32_t FindBestImplementation() |
| 25 | { |
| 26 | std::optional<std::pair<int64_t, uint32_t>> best; |
| 27 | |
| 28 | uint32_t max_impl = Minisketch::MaxImplementation(); |
| 29 | for (uint32_t impl = 0; impl <= max_impl; ++impl) { |
| 30 | std::vector<int64_t> benches; |
| 31 | uint64_t offset = 0; |
| 32 | /* Run a little benchmark with capacity 32, adding 184 entries, and decoding 11 of them once. */ |
| 33 | for (int b = 0; b < 11; ++b) { |
| 34 | if (!Minisketch::ImplementationSupported(BITS, impl)) break; |
| 35 | Minisketch sketch(BITS, impl, 32); |
| 36 | auto start = GetTimeMicros(); |
| 37 | for (uint64_t e = 0; e < 100; ++e) { |
| 38 | sketch.Add(e*1337 + b*13337 + offset); |
| 39 | } |
| 40 | for (uint64_t e = 0; e < 84; ++e) { |
| 41 | sketch.Add(e*1337 + b*13337 + offset); |
| 42 | } |
| 43 | offset += (*sketch.Decode(32))[0]; |
| 44 | auto stop = GetTimeMicros(); |
| 45 | benches.push_back(stop - start); |
| 46 | } |
| 47 | /* Remember which implementation has the best median benchmark time. */ |
| 48 | if (!benches.empty()) { |
| 49 | std::sort(benches.begin(), benches.end()); |
| 50 | if (!best || best->first > benches[5]) { |
| 51 | best = std::make_pair(benches[5], impl); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | assert(best.has_value()); |
| 56 | LogPrintf("Using Minisketch implementation number %i\n", best->second); |
| 57 | return best->second; |
| 58 | } |
| 59 | |
| 60 | uint32_t Minisketch32Implementation() |
| 61 | { |
no test coverage detected