use benchpress for benchmark
This commit is contained in:
parent
d805fd6f15
commit
0cff1cbb1e
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -7,3 +7,6 @@
|
|||||||
[submodule "vendor/spec"]
|
[submodule "vendor/spec"]
|
||||||
path = vendor/spec
|
path = vendor/spec
|
||||||
url = https://github.com/mustache/spec.git
|
url = https://github.com/mustache/spec.git
|
||||||
|
[submodule "vendor/benchpress"]
|
||||||
|
path = vendor/benchpress
|
||||||
|
url = https://github.com/bigdatadev/benchpress.git
|
||||||
|
@ -18,6 +18,7 @@ if(WITH_UNIT_TESTS)
|
|||||||
enable_testing()
|
enable_testing()
|
||||||
include_directories(
|
include_directories(
|
||||||
vendor/Catch/single_include
|
vendor/Catch/single_include
|
||||||
vendor/json.hpp/include)
|
vendor/json.hpp/include
|
||||||
|
vendor/benchpress/src/benchpress)
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
endif()
|
endif()
|
||||||
|
@ -1,44 +1,26 @@
|
|||||||
|
#define BENCHPRESS_CONFIG_MAIN
|
||||||
|
|
||||||
|
#include <benchpress.hpp>
|
||||||
|
|
||||||
#include "mstch/mstch.hpp"
|
#include "mstch/mstch.hpp"
|
||||||
|
|
||||||
#include <chrono>
|
benchpress::auto_register basic_usage("basic usage", [](benchpress::context* ctx) {
|
||||||
#include <iostream>
|
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>"};
|
||||||
|
|
||||||
unsigned long long current_msec() {
|
auto comment_view = mstch::map{
|
||||||
return std::chrono::time_point_cast<std::chrono::milliseconds>(
|
{"header", std::string{"My Post Comments"}},
|
||||||
std::chrono::system_clock::now()).time_since_epoch().count();
|
{"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() {
|
ctx->reset_timer();
|
||||||
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{
|
for (size_t i = 0; i < ctx->num_iterations(); ++i)
|
||||||
{"header", std::string{"My Post Comments"}},
|
mstch::render(comment_tmp, comment_view);
|
||||||
{"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<unsigned long long> 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;
|
|
||||||
}
|
|
||||||
|
1
vendor/benchpress
vendored
Submodule
1
vendor/benchpress
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 469b7c6b0b582389fa397d9b990a0ff1c3b93462
|
Loading…
Reference in New Issue
Block a user