|
1 | 1 | #include "simdjson/jsonparser.h" |
| 2 | +#ifndef _MSC_VER |
2 | 3 | #include <unistd.h> |
| 4 | +#include "linux-perf-events.h" |
| 5 | +#ifdef __linux__ |
| 6 | +#include <libgen.h> |
| 7 | +#endif //__linux__ |
| 8 | +#endif // _MSC_VER |
3 | 9 |
|
4 | 10 | #include "benchmark.h" |
5 | 11 |
|
| 12 | + |
6 | 13 | // #define RAPIDJSON_SSE2 // bad for performance |
7 | 14 | // #define RAPIDJSON_SSE42 // bad for performance |
8 | 15 | #include "rapidjson/document.h" |
@@ -130,6 +137,55 @@ int main(int argc, char *argv[]) { |
130 | 137 | sajson::mutable_string_view(p.size(), buffer)) |
131 | 138 | .is_valid(), |
132 | 139 | true, memcpy(buffer, p.data(), p.size()), repeat, volume, !justdata); |
| 140 | +#ifdef __linux__ |
| 141 | + if(!justdata) { |
| 142 | + vector<int> evts; |
| 143 | + evts.push_back(PERF_COUNT_HW_CPU_CYCLES); |
| 144 | + evts.push_back(PERF_COUNT_HW_INSTRUCTIONS); |
| 145 | + evts.push_back(PERF_COUNT_HW_BRANCH_MISSES); |
| 146 | + evts.push_back(PERF_COUNT_HW_CACHE_REFERENCES); |
| 147 | + evts.push_back(PERF_COUNT_HW_CACHE_MISSES); |
| 148 | + LinuxEvents<PERF_TYPE_HARDWARE> unified(evts); |
| 149 | + vector<unsigned long long> results; |
| 150 | + vector<unsigned long long> stats; |
| 151 | + results.resize(evts.size()); |
| 152 | + stats.resize(evts.size()); |
| 153 | + std::fill(stats.begin(), stats.end(), 0);// unnecessary |
| 154 | + for(size_t i = 0; i < repeat; i++) { |
| 155 | + unified.start(); |
| 156 | + if(json_parse(p, pj) != true) printf("bug\n"); |
| 157 | + unified.end(results); |
| 158 | + std::transform (stats.begin(), stats.end(), results.begin(), stats.begin(), std::plus<unsigned long long>()); |
| 159 | + } |
| 160 | + printf("simdjson: cycles %f instructions %f branchmisses %f cacheref %f cachemisses %f \n", |
| 161 | + stats[0] * 1.0 / repeat, stats[1] * 1.0 / repeat, stats[2] * 1.0 / repeat, stats[3] * 1.0 / repeat, stats[4] * 1.0 / repeat ); |
| 162 | + |
| 163 | + std::fill(stats.begin(), stats.end(), 0); |
| 164 | + for(size_t i = 0; i < repeat; i++) { |
| 165 | + memcpy(buffer, p.data(), p.size()); |
| 166 | + buffer[p.size()] = '\0'; |
| 167 | + unified.start(); |
| 168 | + if(d.ParseInsitu<kParseValidateEncodingFlag>(buffer).HasParseError() != false) printf("bug\n"); |
| 169 | + unified.end(results); |
| 170 | + std::transform (stats.begin(), stats.end(), results.begin(), stats.begin(), std::plus<unsigned long long>()); |
| 171 | + } |
| 172 | + printf("RapidJSON: cycles %f instructions %f branchmisses %f cacheref %f cachemisses %f \n", |
| 173 | + stats[0] * 1.0 / repeat, stats[1] * 1.0 / repeat, stats[2] * 1.0 / repeat, stats[3] * 1.0 / repeat, stats[4] * 1.0 / repeat ); |
| 174 | + |
| 175 | + std::fill(stats.begin(), stats.end(), 0);// unnecessary |
| 176 | + for(size_t i = 0; i < repeat; i++) { |
| 177 | + memcpy(buffer, p.data(), p.size()); |
| 178 | + unified.start(); |
| 179 | + if(sajson::parse(sajson::bounded_allocation(ast_buffer, astbuffersize), |
| 180 | + sajson::mutable_string_view(p.size(), buffer)) |
| 181 | + .is_valid() != true) printf("bug\n"); |
| 182 | + unified.end(results); |
| 183 | + std::transform (stats.begin(), stats.end(), results.begin(), stats.begin(), std::plus<unsigned long long>()); |
| 184 | + } |
| 185 | + printf("sajson: cycles %f instructions %f branchmisses %f cacheref %f cachemisses %f \n", |
| 186 | + stats[0] * 1.0 / repeat, stats[1] * 1.0 / repeat, stats[2] * 1.0 / repeat, stats[3] * 1.0 / repeat, stats[4] * 1.0 / repeat ); |
| 187 | + } |
| 188 | +#endif// __linux__ |
133 | 189 | #ifdef ALLPARSER |
134 | 190 |
|
135 | 191 | std::string json11err; |
|
0 commit comments