#include #include #include "../harness.h" std::vector load_file(char const* const path, size_t* const buf_size) { std::ifstream file(path, std::ios::binary | std::ios::ate); if (!file) { *buf_size = 0; return {}; } std::streamsize size = file.tellg(); file.seekg(0, std::ios::beg); std::vector buffer(static_cast(size)); if (!file.read(buffer.data(), size)) { *buf_size = 0; return {}; } *buf_size = buffer.size(); buffer.push_back(0); // null terminator return buffer; } size_t count_highway_crossings (char* buffer, size_t len); size_t count_highway_crossings_cheat_and_early_out (char* buffer, size_t len); size_t pubmed_len (char* buffer, size_t len); size_t pubmed_len_with_entities (char* buffer, size_t len); int main (void) { FILE* out = fopen("benchmark-results.xml", "wb"); if (!out) goto err; fprintf(out, "\n" "\n" ); size_t buf_size; if (true) { auto buf = load_file("../../dat/yellowstone.osm", &buf_size); char* buffer = buf.data(); if (!buf_size) goto err; bench(count_highway_crossings); buf = load_file("../../dat/yellowstone.osm", &buf_size); buffer = buf.data(); if (!buf_size) goto err; bench(count_highway_crossings_cheat_and_early_out); } if (true) { { auto buf = load_file("../../dat/PMC176545.xml", &buf_size); char* buffer = buf.data(); if (!buf_size) goto err; bench(pubmed_len); } { auto buf = load_file("../../dat/PMC176545.xml", &buf_size); char* buffer = buf.data(); if (!buf_size) goto err; bench(pubmed_len_with_entities); } } fprintf(out, "\n\n" ); goto noerr; err: if (out) fclose(out); fprintf(stderr, "ERROR\n"); return -1; noerr: return 0; }