benchmark2.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Boost.Geometry Index
  2. // Compare performance with std::set using 1-dimensional object
  3. // (i.e. angle, or number line coordiante)
  4. // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
  5. // Use, modification and distribution is subject to the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #include <iostream>
  9. #include <boost/geometry.hpp>
  10. #include <boost/geometry/index/rtree.hpp>
  11. #include <boost/chrono.hpp>
  12. #include <boost/foreach.hpp>
  13. #include <boost/random.hpp>
  14. #include <set>
  15. int main()
  16. {
  17. namespace bg = boost::geometry;
  18. namespace bgi = bg::index;
  19. typedef boost::chrono::thread_clock clock_t;
  20. typedef boost::chrono::duration<float> dur_t;
  21. size_t values_count = 1001;
  22. size_t count_start = 10;
  23. size_t count_stop = 1000;
  24. size_t count_step = 10;
  25. size_t insrem_count = 3000000;
  26. typedef bg::model::point<float, 1, bg::cs::cartesian> P;
  27. //typedef bgi::rtree<P, bgi::linear<8, 3> > RT;
  28. typedef bgi::rtree<P, bgi::quadratic<8, 3> > RT;
  29. //typedef bgi::rtree<P, bgi::rstar<8, 3> > RT;
  30. RT t;
  31. std::set<float> s;
  32. size_t val_i = 0;
  33. for ( size_t curr_count = count_start ; curr_count < count_stop ; curr_count += count_step )
  34. {
  35. // inserting test
  36. {
  37. for (; val_i < curr_count ; ++val_i )
  38. {
  39. float v = val_i / 100.0f;
  40. P p(v);
  41. t.insert(p);
  42. s.insert(v);
  43. }
  44. float v = (val_i+1) / 100.0f;
  45. P test_p(v);
  46. std::cout << t.size() << ' ';
  47. clock_t::time_point start = clock_t::now();
  48. for (size_t i = 0 ; i < insrem_count ; ++i )
  49. {
  50. t.insert(test_p);
  51. t.remove(test_p);
  52. }
  53. dur_t time = clock_t::now() - start;
  54. std::cout << time.count() << ' ';
  55. start = clock_t::now();
  56. for (size_t i = 0 ; i < insrem_count ; ++i )
  57. {
  58. s.insert(v);
  59. s.erase(v);
  60. }
  61. time = clock_t::now() - start;
  62. std::cout << time.count() << ' ';
  63. }
  64. std::cout << '\n';
  65. }
  66. return 0;
  67. }