summaryrefslogtreecommitdiff
path: root/benchmarks/RapidXML/bench.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'benchmarks/RapidXML/bench.cpp')
-rw-r--r--benchmarks/RapidXML/bench.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/benchmarks/RapidXML/bench.cpp b/benchmarks/RapidXML/bench.cpp
new file mode 100644
index 0000000..c057203
--- /dev/null
+++ b/benchmarks/RapidXML/bench.cpp
@@ -0,0 +1,81 @@
+#include <fstream>
+#include <vector>
+
+#include "../harness.h"
+
+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();
+ 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,
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<benchmarks library=\"RapidXML\">\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,
+ "</benchmarks>\n\n"
+ );
+
+ goto noerr;
+ err:
+ if (out) fclose(out);
+ fprintf(stderr, "ERROR\n");
+ return -1;
+ noerr:
+ return 0;
+}
+