mstch/test/benchmark_main.cpp

45 lines
1.4 KiB
C++
Raw Normal View History

2015-04-13 10:18:58 +02:00
#include "mstch/mstch.hpp"
2015-04-13 16:35:12 +02:00
#include <chrono>
#include <iostream>
2015-09-24 11:43:27 +02:00
unsigned long long current_msec() {
return std::chrono::time_point_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now()).time_since_epoch().count();
2015-04-23 12:54:08 +02:00
}
2015-04-13 10:18:58 +02:00
int main() {
2015-04-23 12:54:08 +02:00
std::string comment_tmp{
"<div class=\"comments\"><h3>{{header}}</h3><ul>"
"{{#comments}}<li class=\"comment\"><h5>{{name}}</h5>"
2015-04-23 15:55:18 +02:00
"<p>{{body}}</p></li>{{/comments}}</ul></div>"};
2015-04-23 12:54:08 +02:00
auto comment_view = mstch::map{
{"header", std::string{"My Post Comments"}},
{"comments", mstch::array{
2015-04-16 21:05:59 +02: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!"}}},
2015-04-24 11:54:21 +02:00
mstch::map{{"name", std::string{"George"}}, {"body", std::string{"Thanks for this post!"}}}
}}
};
2015-04-13 10:18:58 +02:00
2015-09-24 11:43:27 +02:00
std::vector<unsigned long long> times;
2015-04-23 12:54:08 +02:00
for (int j = 0; j < 10; j++) {
2015-04-24 14:47:12 +02:00
auto start = current_msec();
2015-04-23 12:54:08 +02:00
for (int i = 0; i < 5000; i++)
mstch::render(comment_tmp, comment_view);
times.push_back(current_msec() - start);
}
2015-04-13 16:35:12 +02:00
2015-04-23 12:54:08 +02:00
float avg = 0;
for (auto i: times)
avg += i;
avg /= times.size();
2015-04-13 16:35:12 +02:00
2015-04-23 12:54:08 +02:00
std::cout << avg << std::endl;
2015-04-13 10:18:58 +02:00
2015-04-23 12:54:08 +02:00
return 0;
2015-04-13 10:18:58 +02:00
}