| 137 | |
| 138 | template <typename Json, typename PR, typename SR> |
| 139 | static void BM_Decode(benchmark::State &state, std::string filename, |
| 140 | std::string_view data) { |
| 141 | Json json; |
| 142 | std::unique_ptr<const PR> pr; |
| 143 | for (auto _ : state) pr = json.parse(data); |
| 144 | |
| 145 | if (!pr) { |
| 146 | state.SkipWithError("Failed to parse file"); |
| 147 | return; |
| 148 | } |
| 149 | |
| 150 | auto sr = pr->stringfy(); |
| 151 | if (!sr) { |
| 152 | state.SkipWithError("Failed to convert to string"); |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | auto new_pr = json.parse(sr->str()); |
| 157 | if (!new_pr) { |
| 158 | state.SkipWithError("Failed to parse string"); |
| 159 | return; |
| 160 | } |
| 161 | |
| 162 | DocStat stat1, stat2; |
| 163 | if (!pr->stat(stat1) || !new_pr->stat(stat2)) { |
| 164 | state.SkipWithError("Failed to get statistic data"); |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | if (stat1 != stat2) { |
| 169 | state.SkipWithError("Stat Verify failed"); |
| 170 | } |
| 171 | |
| 172 | state.SetLabel(filename.data()); |
| 173 | state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(data.size())); |
| 174 | } |
| 175 | |
| 176 | static void regitser_OnDemand() { |
| 177 | std::vector<OnDemand> tests = { |