benchmark_read.cpp
Go to the documentation of this file.
00001 #include <cstdio>
00002 #include <cstdlib>
00003 #include <boost/date_time/posix_time/posix_time_types.hpp>
00004 
00005 #include <megatree/common.h>
00006 #include <megatree/megatree.h>
00007 #include <megatree/storage_factory.h>
00008 #include <megatree/tree_functions.h>
00009 
00010 const unsigned num_queries = 2;
00011 const double resolution = 0.00001;
00012 
00013 using namespace megatree;
00014 
00015 int main (int argc, char** argv)
00016 {
00017   if (argc < 3)
00018   {
00019     printf("Usage: ./benchmark_read  tree_path  cache_size\n");
00020     return -1;
00021   }
00022   boost::posix_time::ptime started, finished;
00023 
00024   // create megatree
00025   boost::shared_ptr<Storage> storage(openStorage(argv[1]));
00026   MegaTree tree(storage, parseNumberSuffixed(argv[2]), true);
00027   NodeHandle root;
00028 
00029   NodeGeometry root_geom(tree.getRootGeometry());
00030   std::vector<double> min_corner(3), max_corner(3);
00031   min_corner[0] = root_geom.getLo(0);
00032   min_corner[1] = root_geom.getLo(1);
00033   min_corner[2] = root_geom.getLo(2);
00034   max_corner[0] = root_geom.getHi(0);
00035   max_corner[1] = root_geom.getHi(1);
00036   max_corner[2] = root_geom.getHi(2);
00037 
00038   // query points
00039   std::vector<double> results, colors;
00040   printf("Loading points in cache with query from %f %f %f to %f %f %f\n",
00041          min_corner[0], min_corner[1], min_corner[2],
00042          max_corner[0], max_corner[1], max_corner[2]);
00043   started = boost::posix_time::microsec_clock::universal_time();
00044   queryRange(tree, min_corner, max_corner, resolution, results, colors);
00045   //tree.resetCount();
00046   printf("Received %d points from the query. %s\n", (int)results.size()/3, tree.toString().c_str());
00047   finished = boost::posix_time::microsec_clock::universal_time();
00048   tree.getRoot(root);
00049   printf("Loading entire tree of %d points in cache took  %.3f seconds.\n",
00050          (int)root.getCount(), 
00051          (finished - started).total_milliseconds() / 1000.0f);
00052   tree.releaseNode(root);
00053 
00054   printf("Query points\n");
00055   started = boost::posix_time::microsec_clock::universal_time();
00056 
00057   for (unsigned int i=0; i<num_queries; i++)
00058   {
00059     results.clear();
00060     colors.clear();
00061     queryRange(tree, min_corner, max_corner, resolution, results, colors);
00062     printf("Received %d points from the query. %s\n", (int)results.size()/3, tree.toString().c_str());
00063     tree.resetCount();
00064   }
00065   
00066   finished = boost::posix_time::microsec_clock::universal_time();
00067 
00068   tree.getRoot(root);
00069   printf("Querying entire tree of %d points %d times took  %.3f seconds.\n",
00070          (int)root.getCount(), num_queries,
00071          (finished - started).total_milliseconds() / 1000.0f);
00072   tree.releaseNode(root);
00073   return 0;
00074 }


megatree_cpp
Author(s): Stuart Glaser
autogenerated on Thu Nov 28 2013 11:30:34