use benchpress for benchmark

This commit is contained in:
Daniel Sipka 2015-10-02 14:06:21 +02:00
parent d805fd6f15
commit 0cff1cbb1e
4 changed files with 27 additions and 40 deletions

View file

@ -1,44 +1,26 @@
#define BENCHPRESS_CONFIG_MAIN
#include <benchpress.hpp>
#include "mstch/mstch.hpp"
#include <chrono>
#include <iostream>
benchpress::auto_register basic_usage("basic usage", [](benchpress::context* ctx) {
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() {
return std::chrono::time_point_cast<std::chrono::milliseconds>(
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{
"<div class=\"comments\"><h3>{{header}}</h3><ul>"
"{{#comments}}<li class=\"comment\"><h5>{{name}}</h5>"
"<p>{{body}}</p></li>{{/comments}}</ul></div>"};
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<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;
}
for (size_t i = 0; i < ctx->num_iterations(); ++i)
mstch::render(comment_tmp, comment_view);
});