compare heap/ptr_vector rule_cache vs stack-based boost::move approach - refs fe9ff21ba9
and #1723
This commit is contained in:
parent
34708c4df0
commit
825a628707
1 changed files with 143 additions and 0 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <set>
|
||||
|
||||
// boost
|
||||
#include <boost/version.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
@ -392,6 +393,137 @@ struct test8
|
|||
}
|
||||
};
|
||||
|
||||
#include <boost/container/vector.hpp>
|
||||
#include <mapnik/rule_cache.hpp>
|
||||
|
||||
struct test9
|
||||
{
|
||||
unsigned iter_;
|
||||
unsigned threads_;
|
||||
unsigned num_rules_;
|
||||
unsigned num_styles_;
|
||||
std::vector<rule> 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<num_rules_;++i) {
|
||||
rules_.push_back(r);
|
||||
}
|
||||
}
|
||||
|
||||
bool validate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
void operator()()
|
||||
{
|
||||
for (unsigned i=0;i<iter_;++i) {
|
||||
boost::container::vector<rule_cache> rule_caches;
|
||||
for (unsigned i=0;i<num_styles_;++i) {
|
||||
rule_cache rc;
|
||||
for (unsigned i=0;i<num_rules_;++i) {
|
||||
rc.add_rule(rules_[i]);
|
||||
}
|
||||
rule_caches.push_back(boost::move(rc));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class rule_cache_old
|
||||
{
|
||||
public:
|
||||
typedef std::vector<rule const*> 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<rule> 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<num_rules_;++i) {
|
||||
rules_.push_back(r);
|
||||
}
|
||||
}
|
||||
|
||||
bool validate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
void operator()()
|
||||
{
|
||||
for (unsigned i=0;i<iter_;++i) {
|
||||
boost::ptr_vector<rule_cache_old> rule_caches;
|
||||
for (unsigned i=0;i<num_styles_;++i) {
|
||||
std::auto_ptr<rule_cache_old> rc(new rule_cache_old);
|
||||
for (unsigned i=0;i<num_rules_;++i) {
|
||||
rc->add_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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue