diff options
| author | steven-vd <steven@vandorp.lu> | 2026-08-16 15:00:32 +0200 |
|---|---|---|
| committer | steven-vd <steven@vandorp.lu> | 2026-08-17 09:31:42 +0200 |
| commit | ee081ca70322cd01d0642fdb1860e6bfbfb48e85 (patch) | |
| tree | 295fdba93b08b24562c6d49e971bbf3425eac50c /benchmarks/pugixml/bench.cpp | |
Diffstat (limited to 'benchmarks/pugixml/bench.cpp')
| -rw-r--r-- | benchmarks/pugixml/bench.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/benchmarks/pugixml/bench.cpp b/benchmarks/pugixml/bench.cpp new file mode 100644 index 0000000..abac120 --- /dev/null +++ b/benchmarks/pugixml/bench.cpp @@ -0,0 +1,76 @@ +#include "../harness.h" +#include <fstream> +#include <vector> + +std::vector<char> 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<char> buffer(static_cast<size_t>(size)); + if (!file.read(buffer.data(), size)) { + *buf_size = 0; + return {}; + } + + *buf_size = buffer.size(); + 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, + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<benchmarks library=\"pugixml\">\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); + + buf = load_file("../../dat/PMC176545.xml", &buf_size); + buffer = buf.data(); + if (!buf_size) goto err; + bench(pubmed_len_with_entities); + } + + fprintf(out, + "</benchmarks>\n\n" + ); + + goto noerr; + err: + if (out) fclose(out); + fprintf(stderr, "ERROR\n"); + return -1; + noerr: + return 0; +} + |
