aboutsummaryrefslogtreecommitdiff
path: root/lib/mstch/benchmark
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-01-16 15:43:04 +0800
committerMistivia <i@mistivia.com>2025-01-16 15:53:58 +0800
commit8689a7c78c50676ea739f52fbcee9f091709f5c0 (patch)
treebbb72c68e5e1753f751133941a402caa43e29a16 /lib/mstch/benchmark
parent00afb767ae37488d99f78363d031b898b1932354 (diff)
add mstch
Diffstat (limited to 'lib/mstch/benchmark')
-rw-r--r--lib/mstch/benchmark/CMakeLists.txt6
-rw-r--r--lib/mstch/benchmark/benchmark_main.cpp26
2 files changed, 32 insertions, 0 deletions
diff --git a/lib/mstch/benchmark/CMakeLists.txt b/lib/mstch/benchmark/CMakeLists.txt
new file mode 100644
index 0000000..fa47f0d
--- /dev/null
+++ b/lib/mstch/benchmark/CMakeLists.txt
@@ -0,0 +1,6 @@
+include_directories(
+ ${CMAKE_SOURCE_DIR}/include
+ ${CMAKE_SOURCE_DIR}/vendor/benchmark/include)
+
+add_executable(mstch_benchmark benchmark_main.cpp)
+target_link_libraries(mstch_benchmark mstch benchmark)
diff --git a/lib/mstch/benchmark/benchmark_main.cpp b/lib/mstch/benchmark/benchmark_main.cpp
new file mode 100644
index 0000000..ad7f8d5
--- /dev/null
+++ b/lib/mstch/benchmark/benchmark_main.cpp
@@ -0,0 +1,26 @@
+#include <benchmark/benchmark.h>
+
+#include "mstch/mstch.hpp"
+
+static void basic_usage(benchmark::State& state) {
+ std::string comment_tmp{
+ "<div class=\"comments\"><h3>{{header}}</h3><ul>"
+ "{{#comments}}<li class=\"comment\"><h5>{{name}}</h5>"
+ "<p>{{body}}</p></li>{{/comments}}</ul></div>"};
+
+ auto comment_view = mstch::map{
+ {"header", std::string{"My Post Comments"}},
+ {"comments", mstch::array{
+ mstch::map{{"name", std::string{"Joe"}}, {"body", std::string{"Thanks for this post!"}}},
+ mstch::map{{"name", std::string{"Sam"}}, {"body", std::string{"Thanks for this post!"}}},
+ mstch::map{{"name", std::string{"Heather"}}, {"body", std::string{"Thanks for this post!"}}},
+ mstch::map{{"name", std::string{"Kathy"}}, {"body", std::string{"Thanks for this post!"}}},
+ mstch::map{{"name", std::string{"George"}}, {"body", std::string{"Thanks for this post!"}}}}}};
+
+ while (state.KeepRunning())
+ mstch::render(comment_tmp, comment_view);
+}
+
+BENCHMARK(basic_usage);
+
+BENCHMARK_MAIN();