From 825a6287071df96cae1c8e84cdbedc9d4ec46da5 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 21 Feb 2013 12:36:16 -0800 Subject: [PATCH] compare heap/ptr_vector rule_cache vs stack-based boost::move approach - refs fe9ff21ba9da6dabef4747f139e and #1723 --- benchmark/run.cpp | 143 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) diff --git a/benchmark/run.cpp b/benchmark/run.cpp index b1b3a8dde..a912ea8cb 100644 --- a/benchmark/run.cpp +++ b/benchmark/run.cpp @@ -14,6 +14,7 @@ #include // boost +#include #include #include #include @@ -392,6 +393,137 @@ struct test8 } }; +#include +#include + +struct test9 +{ + unsigned iter_; + unsigned threads_; + unsigned num_rules_; + unsigned num_styles_; + std::vector rules_; + explicit test9(unsigned iterations, + unsigned threads, + unsigned num_rules, + unsigned num_styles) : + iter_(iterations), + threads_(threads), + num_rules_(num_rules), + num_styles_(num_styles), + rules_() { + mapnik::rule r("test"); + for (unsigned i=0;i rule_caches; + for (unsigned i=0;i rule_ptrs; + rule_cache_old() + : if_rules_(), + else_rules_(), + also_rules_() {} + + void add_rule(rule const& r) + { + if (r.has_else_filter()) + { + else_rules_.push_back(&r); + } + else if (r.has_also_filter()) + { + also_rules_.push_back(&r); + } + else + { + if_rules_.push_back(&r); + } + } + + rule_ptrs const& get_if_rules() const + { + return if_rules_; + } + + rule_ptrs const& get_else_rules() const + { + return else_rules_; + } + + rule_ptrs const& get_also_rules() const + { + return also_rules_; + } + +private: + rule_ptrs if_rules_; + rule_ptrs else_rules_; + rule_ptrs also_rules_; +}; + +struct test10 +{ + unsigned iter_; + unsigned threads_; + unsigned num_rules_; + unsigned num_styles_; + std::vector rules_; + explicit test10(unsigned iterations, + unsigned threads, + unsigned num_rules, + unsigned num_styles) : + iter_(iterations), + threads_(threads), + num_rules_(num_rules), + num_styles_(num_styles), + rules_() { + mapnik::rule r("test"); + for (unsigned i=0;i rule_caches; + for (unsigned i=0;i rc(new rule_cache_old); + for (unsigned i=0;iadd_rule(rules_[i]); + } + rule_caches.push_back(rc); + } + } + } +}; + int main( int argc, char** argv) { if (argc > 0) { @@ -507,6 +639,17 @@ int main( int argc, char** argv) benchmark(runner,"expression parsing by re-using grammar"); } + { + // TODO - only run #if BOOST_VERSION >= 105300 + test9 runner(1000,10,200,50); + benchmark(runner,"rule caching using boost::move"); + } + + { + test10 runner(1000,10,200,50); + benchmark(runner,"rule caching using heap allocation"); + } + std::cout << "...benchmark done\n"; return 0; }