1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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;
}
|