benchmark_write.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/storage_factory.h>
00007 #include <megatree/megatree.h>
00008 #include <megatree/tree_functions.h>
00009 
00010 using namespace megatree;
00011 
00012 
00013 const std::string TREE_PATH = "benchmark_tree";
00014 const double SCANNER_RANGE = 30;
00015 const int POINTS_PER_SCAN = 1000;
00016 const double CAR_STEP = 0.5;
00017 const double SCAN_ACCURACY = 0.001;  // 1 mm accuracy of scans
00018 
00019 
00020 int main (int argc, char** argv)
00021 {
00022   if (argc != 5 && argc != 6)
00023   {
00024     printf("Usage: ./benchmark_write   subtree_width  subfolder_depth  cache_size  num_scans [tree]\n");
00025     return -1;
00026   }
00027   int NUM_SCANS = parseNumberSuffixed(argv[4]);
00028 
00029   std::string tree_path = TREE_PATH;
00030   if (argc > 5)
00031     tree_path = argv[5];
00032 
00033   printf("sizeof(Node) = %zu\n", sizeof(Node));
00034 
00035   boost::posix_time::ptime started, finished, flushed;
00036 
00037   // Deletes any existing tree
00038   megatree::removePath(tree_path);
00039   
00040   double scan_accuracy = SCAN_ACCURACY;
00041   if (argc > 6){
00042     scan_accuracy = atoi(argv[6]);
00043   }
00044     
00045 
00046   // create megatree
00047   std::vector<double> tree_center(3, 0);
00048   double tree_size = 6378000+8850; // radius of the earth + height of Mount Everest
00049   boost::shared_ptr<Storage> storage(openStorage(tree_path));
00050   MegaTree tree(storage, tree_center, tree_size, atoi(argv[1]), atoi(argv[2]), 
00051                 parseNumberSuffixed(argv[3]), scan_accuracy);
00052 
00053   // Generates lots of random numbers
00054   srand(32423);
00055   unsigned int num_random_numbers = 3 * POINTS_PER_SCAN * 100;
00056   std::vector<double> random_numbers;
00057   
00058   random_numbers.reserve(num_random_numbers);
00059   for (size_t i = 0; i < num_random_numbers; ++i) 
00060   {
00061     double rand = drand48() * SCANNER_RANGE;
00062     rand = trunc(rand*1000)/1000;
00063     random_numbers.push_back(rand);
00064   }
00065   std::vector<double> pt(3, 0.0);
00066   std::vector<double> white(3, 255);
00067 
00068   // adding points to tree
00069   printf("Adding %d sorted points.\n", POINTS_PER_SCAN);    
00070   started = boost::posix_time::microsec_clock::universal_time();
00071 
00072   for (int i = 0; i < NUM_SCANS; ++i)
00073   {
00074     if (i*POINTS_PER_SCAN %100000 == 0)
00075     {
00076       printf("Adding point %.1fM, time passed %.1f min, %s\n", 
00077              i*POINTS_PER_SCAN/1e6, 
00078              (boost::posix_time::microsec_clock::universal_time()-started).total_seconds()/60., 
00079              tree.toString().c_str());
00080       dumpTimers();
00081       tree.resetCount();
00082     }
00083     
00084     for (int j=0; j<POINTS_PER_SCAN; j++)
00085     {
00086       pt[0] = ((double)i*CAR_STEP);
00087       pt[1] = random_numbers[(3*j+1)%num_random_numbers];
00088       pt[2] = random_numbers[(3*j+2)%num_random_numbers];
00089       addPoint(tree, pt, white);
00090     }
00091   }
00092   dumpTimers();
00093   finished = boost::posix_time::microsec_clock::universal_time();
00094   tree.flushCache();
00095   flushed = boost::posix_time::microsec_clock::universal_time();
00096   printf("Adding %d points took  %.3f seconds. Writing to disk took %.3f seconds\n",
00097          NUM_SCANS * POINTS_PER_SCAN,
00098          (flushed - started).total_milliseconds() / 1000.0f,
00099          (flushed - finished).total_milliseconds() / 1000.0f);
00100   
00101   return 0;
00102 }


megatree_cpp
Author(s): Stuart Glaser
autogenerated on Mon Dec 2 2013 13:01:28