| 67 | } |
| 68 | |
| 69 | void BenchLinearizeOptimallyPerCost(benchmark::Bench& bench, const std::string& name, const std::vector<std::vector<uint8_t>>& serializeds) |
| 70 | { |
| 71 | for (const auto& serialized : serializeds) { |
| 72 | SpanReader reader{serialized}; |
| 73 | DepGraph<BitSet<64>> depgraph; |
| 74 | reader >> Using<DepGraphFormatter>(depgraph); |
| 75 | auto bench_name = strprintf("%s_%utx_%udep", name, depgraph.TxCount(), depgraph.CountDependencies()); |
| 76 | |
| 77 | // Determine the cost of 100 rng_seeds. |
| 78 | uint64_t total_cost = 0; |
| 79 | for (uint64_t iter = 0; iter < 100; ++iter) { |
| 80 | auto [_lin, optimal, cost] = Linearize(depgraph, /*max_cost=*/10000000, /*rng_seed=*/iter, IndexTxOrder{}); |
| 81 | total_cost += cost; |
| 82 | } |
| 83 | |
| 84 | // Benchmark the time per cost. |
| 85 | bench.name(bench_name).unit("cost").batch(total_cost).run([&] { |
| 86 | uint64_t recompute_cost = 0; |
| 87 | for (uint64_t iter = 0; iter < 100; ++iter) { |
| 88 | auto [_lin, optimal, cost] = Linearize(depgraph, /*max_cost=*/10000000, /*rng_seed=*/iter, IndexTxOrder{}); |
| 89 | assert(optimal); |
| 90 | recompute_cost += cost; |
| 91 | } |
| 92 | assert(total_cost == recompute_cost); |
| 93 | }); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | } // namespace |
| 98 |
no test coverage detected