Timing multi-threaded code
parent
5e5457b390
commit
5cfe761f27
|
@ -22,26 +22,9 @@
|
||||||
#include <gtsam/slam/GeneralSFMFactor.h>
|
#include <gtsam/slam/GeneralSFMFactor.h>
|
||||||
#include <gtsam/geometry/Pose3.h>
|
#include <gtsam/geometry/Pose3.h>
|
||||||
#include <gtsam/geometry/Cal3_S2.h>
|
#include <gtsam/geometry/Cal3_S2.h>
|
||||||
|
#include "timeLinearize.h"
|
||||||
|
|
||||||
#include <time.h>
|
#define time timeMultiThreaded
|
||||||
#include <iostream>
|
|
||||||
#include <iomanip> // std::setprecision
|
|
||||||
using namespace std;
|
|
||||||
using namespace gtsam;
|
|
||||||
|
|
||||||
static const int n = 100000;
|
|
||||||
|
|
||||||
void time(const string& str, const NonlinearFactor& f, const Values& values) {
|
|
||||||
long timeLog = clock();
|
|
||||||
GaussianFactor::shared_ptr gf;
|
|
||||||
for (int i = 0; i < n; i++)
|
|
||||||
gf = f.linearize(values);
|
|
||||||
long timeLog2 = clock();
|
|
||||||
double seconds = (double) (timeLog2 - timeLog) / CLOCKS_PER_SEC;
|
|
||||||
// cout << ((double) n / seconds) << " calls/second" << endl;
|
|
||||||
cout << setprecision(3);
|
|
||||||
cout << str << ((double) seconds * 1000000 / n) << " musecs/call" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::shared_ptr<Cal3_S2> fixedK(new Cal3_S2());
|
boost::shared_ptr<Cal3_S2> fixedK(new Cal3_S2());
|
||||||
|
|
||||||
|
@ -73,20 +56,24 @@ int main() {
|
||||||
// Dedicated factor
|
// Dedicated factor
|
||||||
// Oct 3, 2014, Macbook Air
|
// Oct 3, 2014, Macbook Air
|
||||||
// 4.2 musecs/call
|
// 4.2 musecs/call
|
||||||
GeneralSFMFactor2<Cal3_S2> f1(z, model, 1, 2, 3);
|
NonlinearFactor::shared_ptr f1 =
|
||||||
|
boost::make_shared<GeneralSFMFactor2<Cal3_S2> >(z, model, 1, 2, 3);
|
||||||
time("GeneralSFMFactor2<Cal3_S2> : ", f1, values);
|
time("GeneralSFMFactor2<Cal3_S2> : ", f1, values);
|
||||||
|
|
||||||
// ExpressionFactor
|
// ExpressionFactor
|
||||||
// Oct 3, 2014, Macbook Air
|
// Oct 3, 2014, Macbook Air
|
||||||
// 20.3 musecs/call
|
// 20.3 musecs/call
|
||||||
ExpressionFactor<Point2> f2(model, z,
|
NonlinearFactor::shared_ptr f2 =
|
||||||
uncalibrate(K, project(transform_to(x, p))));
|
boost::make_shared<ExpressionFactor<Point2> >(model, z,
|
||||||
|
uncalibrate(K, project(transform_to(x, p))));
|
||||||
time("Bin(Leaf,Un(Bin(Leaf,Leaf))): ", f2, values);
|
time("Bin(Leaf,Un(Bin(Leaf,Leaf))): ", f2, values);
|
||||||
|
|
||||||
// ExpressionFactor ternary
|
// ExpressionFactor ternary
|
||||||
// Oct 3, 2014, Macbook Air
|
// Oct 3, 2014, Macbook Air
|
||||||
// 20.3 musecs/call
|
// 20.3 musecs/call
|
||||||
ExpressionFactor<Point2> f3(model, z, project3(x, p, K));
|
NonlinearFactor::shared_ptr f3 =
|
||||||
|
boost::make_shared<ExpressionFactor<Point2> >(model, z,
|
||||||
|
project3(x, p, K));
|
||||||
time("Ternary(Leaf,Leaf,Leaf) : ", f3, values);
|
time("Ternary(Leaf,Leaf,Leaf) : ", f3, values);
|
||||||
|
|
||||||
// CALIBRATED
|
// CALIBRATED
|
||||||
|
@ -94,14 +81,16 @@ int main() {
|
||||||
// Dedicated factor
|
// Dedicated factor
|
||||||
// Oct 3, 2014, Macbook Air
|
// Oct 3, 2014, Macbook Air
|
||||||
// 3.4 musecs/call
|
// 3.4 musecs/call
|
||||||
GenericProjectionFactor<Pose3, Point3> g1(z, model, 1, 2, fixedK);
|
NonlinearFactor::shared_ptr g1 = boost::make_shared<
|
||||||
|
GenericProjectionFactor<Pose3, Point3> >(z, model, 1, 2, fixedK);
|
||||||
time("GenericProjectionFactor<P,P>: ", g1, values);
|
time("GenericProjectionFactor<P,P>: ", g1, values);
|
||||||
|
|
||||||
// ExpressionFactor
|
// ExpressionFactor
|
||||||
// Oct 3, 2014, Macbook Air
|
// Oct 3, 2014, Macbook Air
|
||||||
// 16.0 musecs/call
|
// 16.0 musecs/call
|
||||||
ExpressionFactor<Point2> g2(model, z,
|
NonlinearFactor::shared_ptr g2 =
|
||||||
uncalibrate(Cal3_S2_(*fixedK), project(transform_to(x, p))));
|
boost::make_shared<ExpressionFactor<Point2> >(model, z,
|
||||||
|
uncalibrate(Cal3_S2_(*fixedK), project(transform_to(x, p))));
|
||||||
time("Bin(Cnst,Un(Bin(Leaf,Leaf))): ", g2, values);
|
time("Bin(Cnst,Un(Bin(Leaf,Leaf))): ", g2, values);
|
||||||
|
|
||||||
// ExpressionFactor, optimized
|
// ExpressionFactor, optimized
|
||||||
|
@ -109,7 +98,9 @@ int main() {
|
||||||
// 9.0 musecs/call
|
// 9.0 musecs/call
|
||||||
typedef PinholeCamera<Cal3_S2> Camera;
|
typedef PinholeCamera<Cal3_S2> Camera;
|
||||||
typedef Expression<Camera> Camera_;
|
typedef Expression<Camera> Camera_;
|
||||||
ExpressionFactor<Point2> g3(model, z, Point2_(myProject, x, p));
|
NonlinearFactor::shared_ptr g3 =
|
||||||
|
boost::make_shared<ExpressionFactor<Point2> >(model, z,
|
||||||
|
Point2_(myProject, x, p));
|
||||||
time("Binary(Leaf,Leaf) : ", g3, values);
|
time("Binary(Leaf,Leaf) : ", g3, values);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
* 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 timeLinearize.h
|
||||||
|
* @brief time linearize
|
||||||
|
* @author Frank Dellaert
|
||||||
|
* @date October 10, 2014
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gtsam/nonlinear/NonlinearFactorGraph.h>
|
||||||
|
#include <gtsam/linear/GaussianFactorGraph.h>
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <iomanip> // std::setprecision
|
||||||
|
using namespace std;
|
||||||
|
using namespace gtsam;
|
||||||
|
|
||||||
|
static const int n = 1000000;
|
||||||
|
|
||||||
|
void timeSingleThreaded(const string& str, const NonlinearFactor::shared_ptr& f,
|
||||||
|
const Values& values) {
|
||||||
|
long timeLog = clock();
|
||||||
|
GaussianFactor::shared_ptr gf;
|
||||||
|
for (int i = 0; i < n; i++)
|
||||||
|
gf = f->linearize(values);
|
||||||
|
long timeLog2 = clock();
|
||||||
|
double seconds = (double) (timeLog2 - timeLog) / CLOCKS_PER_SEC;
|
||||||
|
// cout << ((double) n / seconds) << " calls/second" << endl;
|
||||||
|
cout << setprecision(3);
|
||||||
|
cout << str << ((double) seconds * 1000000 / n) << " musecs/call" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void timeMultiThreaded(const string& str, const NonlinearFactor::shared_ptr& f,
|
||||||
|
const Values& values) {
|
||||||
|
NonlinearFactorGraph graph;
|
||||||
|
for (int i = 0; i < n; i++)
|
||||||
|
graph.push_back(f);
|
||||||
|
long timeLog = clock();
|
||||||
|
GaussianFactorGraph::shared_ptr gfg = graph.linearize(values);
|
||||||
|
long timeLog2 = clock();
|
||||||
|
double seconds = (double) (timeLog2 - timeLog) / CLOCKS_PER_SEC;
|
||||||
|
// cout << ((double) n / seconds) << " calls/second" << endl;
|
||||||
|
cout << setprecision(3);
|
||||||
|
cout << str << ((double) seconds * 1000000 / n) << " musecs/call" << endl;
|
||||||
|
}
|
||||||
|
|
|
@ -18,25 +18,9 @@
|
||||||
|
|
||||||
#include <gtsam_unstable/slam/expressions.h>
|
#include <gtsam_unstable/slam/expressions.h>
|
||||||
#include <gtsam_unstable/nonlinear/ExpressionFactor.h>
|
#include <gtsam_unstable/nonlinear/ExpressionFactor.h>
|
||||||
|
#include "timeLinearize.h"
|
||||||
|
|
||||||
#include <time.h>
|
#define time timeMultiThreaded
|
||||||
#include <iostream>
|
|
||||||
#include <iomanip> // std::setprecision
|
|
||||||
using namespace std;
|
|
||||||
using namespace gtsam;
|
|
||||||
|
|
||||||
static const int n = 1000000;
|
|
||||||
|
|
||||||
void time(const NonlinearFactor& f, const Values& values) {
|
|
||||||
long timeLog = clock();
|
|
||||||
GaussianFactor::shared_ptr gf;
|
|
||||||
for (int i = 0; i < n; i++)
|
|
||||||
gf = f.linearize(values);
|
|
||||||
long timeLog2 = clock();
|
|
||||||
double seconds = (double) (timeLog2 - timeLog) / CLOCKS_PER_SEC;
|
|
||||||
cout << setprecision(3);
|
|
||||||
cout << ((double) seconds * 1000000 / n) << " musecs/call" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
|
@ -59,12 +43,13 @@ int main() {
|
||||||
// Oct 3, 2014, Macbook Air
|
// Oct 3, 2014, Macbook Air
|
||||||
// 20.3 musecs/call
|
// 20.3 musecs/call
|
||||||
//#define TERNARY
|
//#define TERNARY
|
||||||
|
NonlinearFactor::shared_ptr f = boost::make_shared<ExpressionFactor<Point2> >
|
||||||
#ifdef TERNARY
|
#ifdef TERNARY
|
||||||
ExpressionFactor<Point2> f(model, z, project3(x, p, K));
|
(model, z, project3(x, p, K));
|
||||||
#else
|
#else
|
||||||
ExpressionFactor<Point2> f(model, z, uncalibrate(K, project(transform_to(x, p))));
|
(model, z, uncalibrate(K, project(transform_to(x, p))));
|
||||||
#endif
|
#endif
|
||||||
time(f, values);
|
time("timing:", f, values);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue