optimizations

This commit is contained in:
Daniel Sipka 2015-04-13 16:35:12 +02:00
parent 6369a38800
commit e10e9b6d86
14 changed files with 156 additions and 55 deletions

View file

@ -1,6 +1,33 @@
#include "mstch/mstch.hpp"
#include <chrono>
#include <iostream>
int main() {
std::string complex_html{
"<h1>{{header}}</h1>\n"
"{{#list}}\n"
" <ul>\n"
" {{#item}}\n"
" {{#current}}\n"
" <li><strong>{{name}}</strong></li>\n"
" {{/current}}\n"
" {{#link}}\n"
" <li><a href=\"{{url}}\">{{name}}</a></li>\n"
" {{/link}}\n"
" {{/item}}\n"
" </ul>\n"
"{{/list}}\n"
"{{#empty}}\n"
" <p>The list is empty.</p>\n"
"{{/empty}}\n"
"{{^empty}}\n"
" <p>The list is not empty.</p>\n"
"{{/empty}}"
};
std::string comment_tmp{
"<div class=\"comments\"><h3>{{header}}</h3><ul>"
"{{#comments}}<li class=\"comment\"><h5>{{name}}</h5>"
@ -17,8 +44,23 @@ int main() {
}}
};
for(int i = 0; i < 5000; i++)
mstch::render(comment_tmp, comment_view);
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;
return 0;
}