|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r80833 - sandbox-branches/geometry/index_dev/tests
From: adam.wulkiewicz_at_[hidden]
Date: 2012-10-03 17:04:14
Author: awulkiew
Date: 2012-10-03 17:04:13 EDT (Wed, 03 Oct 2012)
New Revision: 80833
URL: http://svn.boost.org/trac/boost/changeset/80833
Log:
added quick speed test
Added:
sandbox-branches/geometry/index_dev/tests/additional_speed.cpp (contents, props changed)
Added: sandbox-branches/geometry/index_dev/tests/additional_speed.cpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index_dev/tests/additional_speed.cpp 2012-10-03 17:04:13 EDT (Wed, 03 Oct 2012)
@@ -0,0 +1,129 @@
+#include <windows.h>
+
+#include <iostream>
+#include <fstream>
+
+#include <boost/geometry/extensions/index/rtree/rtree.hpp>
+#include <boost/geometry/extensions/index/inserter.hpp>
+
+#include <boost/geometry/extensions/index/rtree/visitors/are_boxes_ok.hpp>
+#include <boost/geometry/extensions/index/rtree/visitors/are_levels_ok.hpp>
+
+#include <boost/timer.hpp>
+#include <boost/foreach.hpp>
+#include <boost/random.hpp>
+
+#include <boost/pool/pool_alloc.hpp>
+
+int main()
+{
+ boost::timer tim;
+
+ namespace bg = boost::geometry;
+ namespace bgi = bg::index;
+
+ size_t values_count = 1000000;
+ size_t tests_count = 10;
+ size_t queries_count = 100000;
+
+ std::vector< std::pair<float, float> > coords;
+
+ //randomize values
+ {
+ boost::mt19937 rng;
+ //rng.seed(static_cast<unsigned int>(std::time(0)));
+ float max_val = static_cast<float>(values_count / 2);
+ boost::uniform_real<float> range(-max_val, max_val);
+ boost::variate_generator<boost::mt19937&, boost::uniform_real<float> > rnd(rng, range);
+
+ coords.reserve(values_count);
+
+ std::cout << "randomizing data\n";
+ for ( size_t i = 0 ; i < values_count ; ++i )
+ {
+ coords.push_back(std::make_pair(rnd(), rnd()));
+ }
+ std::cout << "randomized\n";
+ }
+
+ //typedef bg::model::d2::point_xy<double> P;
+ typedef bg::model::point<double, 2, bg::cs::cartesian> P;
+ typedef bg::model::box<P> B;
+ //typedef bgi::rtree<B, bgi::linear<32, 8> > RT;
+ //typedef bgi::rtree<B, bgi::runtime::linear > RT;
+ typedef bgi::rtree<B, bgi::quadratic<32, 8> > RT;
+ // typedef bgi::rtree<B, bgi::runtime::quadratic > RT;
+ //typedef bgi::rtree<B, bgi::rstar<32, 8> > RT;
+ //typedef bgi::rtree<B, bgi::runtime::rstar > RT;
+
+ for ( ;; )
+ {
+ RT t;
+ //RT t(bgi::runtime::linear(32, 8));
+ //RT t(bgi::runtime::quadratic(32, 8));
+ //RT t(bgi::runtime::rstar(32, 8));
+
+ // inserting test
+ {
+ std::cout << "rtree inserting time test... ("
+ << values_count << ")\n";
+ tim.restart();
+ for (size_t i = 0 ; i < values_count ; ++i )
+ {
+ float x = coords[i].first;
+ float y = coords[i].second;
+ B b(P(x - 0.5f, y - 0.5f), P(x + 0.5f, y + 0.5f));
+
+ t.insert(b);
+ }
+ std::cout << "time: " << tim.elapsed() << "s\n";
+ }
+
+ {
+ float x = coords[0].first;
+ float y = coords[0].second;
+ B b(P(x - 0.5f, y - 0.5f), P(x + 0.5f, y + 0.5f));
+ t.remove(b);
+ }
+
+ std::vector<B> result;
+ result.reserve(100);
+
+ // query test
+ {
+ std::cout << "query(B) searching time test... ("
+ << queries_count << ")\n";
+ tim.restart();
+ size_t temp = 0;
+ for (size_t i = 0 ; i < queries_count ; ++i )
+ {
+ float x = coords[i].first;
+ float y = coords[i].second;
+ result.clear();
+ t.query(B(P(x - 10, y - 10), P(x + 10, y + 10)), std::back_inserter(result));
+ temp += result.size();
+ }
+ std::cout << "time: " << tim.elapsed() << "s\n";
+ std::cout << "found: " << temp << "\n";
+ }
+
+ // searching test
+ {
+ std::cout << "nearest 5 searching time test... ("
+ << queries_count / 10 << ")\n";
+ tim.restart();
+ size_t temp = 0;
+ for (size_t i = 0 ; i < queries_count / 10 ; ++i )
+ {
+ float x = coords[i].first + 100;
+ float y = coords[i].second + 100;
+ result.clear();
+ temp += t.nearest(P(x, y), 5, std::back_inserter(result));
+ }
+ std::cout << "time: " << tim.elapsed() << "s\n";
+ std::cout << "found: " << temp << "\n";
+ }
+ }
+
+ return 0;
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk