mstch/test/benchmark_main.cpp

43 lines
1.5 KiB
C++
Raw Normal View History

2015-04-13 16:18:58 +08:00
#include "mstch/mstch.hpp"
2015-04-13 22:35:12 +08:00
#include <chrono>
#include <iostream>
2015-04-13 16:18:58 +08:00
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>"
};
2015-04-17 03:05:59 +08:00
auto comment_view = mstch::map{
2015-04-13 16:18:58 +08:00
{"header", std::string{"My Post Comments"}},
{"comments", mstch::array{
2015-04-17 03:05:59 +08:00
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!"}}}
2015-04-13 16:18:58 +08:00
}}
};
2015-04-13 22:35:12 +08:00
std::vector<int> times;
for(int j = 0; j < 10; j++) {
unsigned long start =
std::chrono::system_clock::now().time_since_epoch() /
std::chrono::milliseconds(1);
for(int i = 0; i < 5000; i++) {
mstch::render(comment_tmp, comment_view);
}
times.push_back((std::chrono::system_clock::now().time_since_epoch() /
std::chrono::milliseconds(1)) - start);
}
float avg = 0;
for(int i: times) avg += i;
avg /= times.size();
std::cout << avg << std::endl;
2015-04-13 16:18:58 +08:00
return 0;
}