diff --git a/.gitmodules b/.gitmodules index 07d708c..4da6987 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "vendor/spec"] path = vendor/spec url = https://github.com/mustache/spec.git +[submodule "vendor/benchpress"] + path = vendor/benchpress + url = https://github.com/bigdatadev/benchpress.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a44474..8868cf7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ if(WITH_UNIT_TESTS) enable_testing() include_directories( vendor/Catch/single_include - vendor/json.hpp/include) + vendor/json.hpp/include + vendor/benchpress/src/benchpress) add_subdirectory(test) endif() diff --git a/test/benchmark_main.cpp b/test/benchmark_main.cpp index d551a5b..913b2cc 100644 --- a/test/benchmark_main.cpp +++ b/test/benchmark_main.cpp @@ -1,44 +1,26 @@ +#define BENCHPRESS_CONFIG_MAIN + +#include + #include "mstch/mstch.hpp" -#include -#include +benchpress::auto_register basic_usage("basic usage", [](benchpress::context* ctx) { + std::string comment_tmp{ + "

{{header}}

    " + "{{#comments}}
  • {{name}}
    " + "

    {{body}}

  • {{/comments}}
"}; -unsigned long long current_msec() { - return std::chrono::time_point_cast( - std::chrono::system_clock::now()).time_since_epoch().count(); -} + 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!"}}}}}}; -int main() { - std::string comment_tmp{ - "

{{header}}

    " - "{{#comments}}
  • {{name}}
    " - "

    {{body}}

  • {{/comments}}
"}; + ctx->reset_timer(); - 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!"}}} - }} - }; - - std::vector times; - for (int j = 0; j < 10; j++) { - auto start = current_msec(); - for (int i = 0; i < 5000; i++) - mstch::render(comment_tmp, comment_view); - times.push_back(current_msec() - start); - } - - float avg = 0; - for (auto i: times) - avg += i; - avg /= times.size(); - - std::cout << avg << std::endl; - - return 0; -} + for (size_t i = 0; i < ctx->num_iterations(); ++i) + mstch::render(comment_tmp, comment_view); +}); diff --git a/vendor/benchpress b/vendor/benchpress new file mode 160000 index 0000000..469b7c6 --- /dev/null +++ b/vendor/benchpress @@ -0,0 +1 @@ +Subproject commit 469b7c6b0b582389fa397d9b990a0ff1c3b93462