/* ---------------------------------------------------------------------------- * GTSAM Copyright 2010, Georgia Tech Research Corporation, * Atlanta, Georgia 30332-0415 * All Rights Reserved * Authors: Frank Dellaert, et al. (see THANKS for the full author list) * See LICENSE for the license information * -------------------------------------------------------------------------- */ /** * @file timeFactorOverhead.cpp * @brief Compares times of solving large single-factor graphs with their multi-factor equivalents. * @author Richard Roberts * @created Aug 20, 2010 */ #include #include #include #include #include #include #include using namespace gtsam; using namespace std; typedef EliminationTree GaussianEliminationTree; static boost::variate_generator > rg(boost::mt19937(), boost::uniform_real<>(0.0, 1.0)); int main(int argc, char *argv[]) { Index key = 0; size_t vardim = 2; size_t blockdim = 1; size_t nBlocks = 2000; size_t nTrials = 10; double blockbuild, blocksolve, combbuild, combsolve; cout << "\n1 variable of dimension " << vardim << ", " << nBlocks << " blocks of dimension " << blockdim << "\n"; cout << nTrials << " trials\n"; ///////////////////////////////////////////////////////////////////////////// // Timing test with blockwise Gaussian factor graphs { // Build GFG's cout << "Building blockwise Gaussian factor graphs... "; cout.flush(); boost::timer timer; timer.restart(); vector blockGfgs; blockGfgs.reserve(nTrials); for(size_t trial=0; trialeliminate()); VectorValues soln(optimize(*gbn)); } blocksolve = timer.elapsed(); cout << blocksolve << " s" << endl; } ///////////////////////////////////////////////////////////////////////////// // Timing test with combined-factor Gaussian factor graphs { // Build GFG's cout << "Building combined-factor Gaussian factor graphs... "; cout.flush(); boost::timer timer; timer.restart(); vector combGfgs; for(size_t trial=0; trialeliminate()); VectorValues soln(optimize(*gbn)); } combsolve = timer.elapsed(); cout << combsolve << " s" << endl; } ///////////////////////////////////////////////////////////////////////////// // Print per-graph times cout << "\nPer-factor-graph times for building and solving\n"; cout << "Blockwise: total " << (1000.0*(blockbuild+blocksolve)/double(nTrials)) << " build " << (1000.0*blockbuild/double(nTrials)) << " solve " << (1000.0*blocksolve/double(nTrials)) << " ms/graph\n"; cout << "Combined: total " << (1000.0*(combbuild+combsolve)/double(nTrials)) << " build " << (1000.0*combbuild/double(nTrials)) << " solve " << (1000.0*combsolve/double(nTrials)) << " ms/graph\n"; cout << "Fraction of time spent in overhead\n" << " total " << (((blockbuild+blocksolve)-(combbuild+combsolve)) / (blockbuild+blocksolve)) << "\n" << " build " << ((blockbuild-combbuild) / blockbuild) << "\n" << " solve " << ((blocksolve-combsolve) / blocksolve) << "\n"; cout << endl; return 0; }