benchmark
This commit is contained in:
parent
c4b5eb8664
commit
26aa05fccc
1 changed files with 36 additions and 12 deletions
|
@ -1,18 +1,42 @@
|
||||||
|
#include "mstch/mstch.hpp"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <mstch/mstch.hpp>
|
unsigned long current_msec() {
|
||||||
|
return std::chrono::system_clock::now().time_since_epoch() /
|
||||||
|
std::chrono::milliseconds(1);
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
std::string view{"{{#names}}Hi {{name}}!\n{{/names}}"};
|
std::string comment_tmp{
|
||||||
mstch::map context{
|
"<div class=\"comments\"><h3>{{header}}</h3><ul>"
|
||||||
{"names", mstch::array{
|
"{{#comments}}<li class=\"comment\"><h5>{{name}}</h5>"
|
||||||
mstch::map{{"name", std::string{"Chris"}}},
|
"<p>{{body}}</p></li>{{/comments}}</ul></div>"};
|
||||||
mstch::map{{"name", std::string{"Mark"}}},
|
|
||||||
mstch::map{{"name", std::string{"Scott"}}},
|
|
||||||
}}
|
|
||||||
};
|
|
||||||
|
|
||||||
std::cout << mstch::render(view, context) << std::endl;
|
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!"}}}}}};
|
||||||
|
|
||||||
return 0;
|
std::vector<unsigned long> times;
|
||||||
}
|
for (int j = 0; j < 10; j++) {
|
||||||
|
unsigned long 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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue