summaryrefslogtreecommitdiff
path: root/benchmarks/imxml/count_highway_crossings.c
diff options
context:
space:
mode:
Diffstat (limited to 'benchmarks/imxml/count_highway_crossings.c')
-rw-r--r--benchmarks/imxml/count_highway_crossings.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/benchmarks/imxml/count_highway_crossings.c b/benchmarks/imxml/count_highway_crossings.c
new file mode 100644
index 0000000..f758a05
--- /dev/null
+++ b/benchmarks/imxml/count_highway_crossings.c
@@ -0,0 +1,64 @@
+#define IMXML_LINUX
+#define IMXML_SIMD_DEFAULT AVX2
+#define IMXML_NO_SUPPORT_ENTITIES
+#define IMXML_NO_SUPPORT_SINGLE_QUOTES
+#define IMXML_NO_SUPPORT_COMMENTS
+#define IMXML_NO_SUPPORT_CDATA
+#define IMXML_NO_SUPPORT_CUSTOM_ENTITIES
+#define THREADLOCAL
+#define IMXML_NO_CHECK_BOUNDS
+#define IMXML_NO_SUPPORT_NAMESPACES
+#define IMXML_IMPLEMENTATION
+#include <imxml.h>
+
+size_t count_highway_crossings_cheat_and_early_out (char const* const buffer) {
+ XmlParser p = {.head = buffer};
+ size_t total = 0;
+
+ while (true) {
+ ImxmlString tag = xml_tag(&p);
+ if (imxml_streql(tag, imxml_strlit("tag"))) {
+ ImxmlString key = xml_value(&p);
+ if (!imxml_streql(key, imxml_strlit("highway"))) continue;
+ ImxmlString value = xml_value(&p);
+ if (imxml_streql(value, imxml_strlit("crossing"))) {
+ total += 1;
+ }
+ } else if (imxml_streql(tag, imxml_strlit("way"))) {
+ break;
+ }
+ }
+
+ return total;
+}
+
+size_t count_highway_crossings (char const* const buffer) {
+ XmlParser p = {.head = buffer};
+ size_t total = 0;
+
+ while (true) {
+ ImxmlString tag = xml_tag(&p);
+ if (imxml_streql(tag, imxml_strlit("node"))) {
+ if (xml_has_children(&p)) {
+ while (true) {
+ tag = xml_tag(&p);
+ if (imxml_streql(tag, imxml_strlit("/node"))) break;
+ ImxmlString key = xml_value(&p);
+ if (!imxml_streql(key, imxml_strlit("highway"))) continue;
+ ImxmlString value = xml_value(&p);
+ if (imxml_streql(value, imxml_strlit("crossing"))) {
+ total += 1;
+ }
+ }
+ }
+ } else if (imxml_streql(tag, imxml_strlit("/osm"))) {
+ /* encountered non-node tag, which means we can early-out.
+ * Alternatively, we could check if tag == "/osm", but then we'd
+ * just be skipping over all the <way> and <relation> tags */
+ break;
+ }
+ }
+
+ return total;
+}
+