| 54 | |
| 55 | template <typename Json, typename PR, typename SR> |
| 56 | static void BM_Stat(benchmark::State &state, std::string filename, |
| 57 | std::string_view data) { |
| 58 | Json json; |
| 59 | std::unique_ptr<const PR> pr; |
| 60 | pr = json.parse(data); |
| 61 | |
| 62 | if (!pr) { |
| 63 | state.SkipWithError("Failed to parse file"); |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | auto sr = pr->stringfy(); |
| 68 | if (!sr) { |
| 69 | state.SkipWithError("Failed to convert to string"); |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | auto new_pr = json.parse(sr->str()); |
| 74 | if (!new_pr) { |
| 75 | state.SkipWithError("Failed to parse string"); |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | DocStat stat1, stat2; |
| 80 | |
| 81 | bool stat_re; |
| 82 | for (auto _ : state) stat_re = pr->stat(stat1); |
| 83 | |
| 84 | if (!stat_re || !new_pr->stat(stat2)) { |
| 85 | state.SkipWithError("Failed to get statistic data"); |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | if (stat1 != stat2) { |
| 90 | state.SkipWithError("Stat Verify failed"); |
| 91 | } |
| 92 | |
| 93 | state.SetLabel(filename.data()); |
| 94 | state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(data.size())); |
| 95 | } |
| 96 | |
| 97 | template <typename Json, typename PR, typename SR> |
| 98 | static void BM_Find(benchmark::State &state, std::string filename, |