diff --git a/benchmark/unicycle.cpp b/benchmark/unicycle.cpp index 07516cf466c7a103d3aec03adc2bd6410874e7d8..0556af1c692ddb201b347b9d0ba4b2f734bc934f 100644 --- a/benchmark/unicycle.cpp +++ b/benchmark/unicycle.cpp @@ -1,12 +1,17 @@ #include "crocoddyl/core/actions/unicycle.hpp" #include "crocoddyl/core/utils/callbacks.hpp" #include "crocoddyl/core/solvers/ddp.hpp" -#include <ctime> +#include<time.h> + +#ifdef WITH_MULTITHREADING +#include<omp.h> +#endif //WITH_MULTITHREADING + int main() { bool CALLBACKS = false; unsigned int N = 200; // number of nodes - unsigned int T = 5e3; // number of trials + unsigned int T = 10; // number of trials unsigned int MAXITER = 1; using namespace crocoddyl; @@ -35,19 +40,36 @@ int main() { cbs.push_back(new CallbackVerbose()); ddp.setCallbacks(cbs); } - + struct timespec start, finish; + double elapsed; // Solving the optimal control problem - std::clock_t c_start, c_end; Eigen::ArrayXd duration(T); for (unsigned int i = 0; i < T; ++i) { - c_start = std::clock(); + clock_gettime(CLOCK_MONOTONIC, &start); ddp.solve(xs, us, MAXITER); - c_end = std::clock(); - duration[i] = 1e3 * (double)(c_end - c_start) / CLOCKS_PER_SEC; + clock_gettime(CLOCK_MONOTONIC, &finish); + elapsed = (finish.tv_sec - start.tv_sec)*1000000.0; + elapsed += (finish.tv_nsec - start.tv_nsec)/ 1000.0; + + duration[i] = elapsed; //in us } double avrg_duration = duration.sum() / T; double min_duration = duration.minCoeff(); double max_duration = duration.maxCoeff(); - std::cout << "CPU time [ms]: " << avrg_duration << " (" << min_duration << "-" << max_duration << ")" << std::endl; + std::cout << "Wall time solve [us]: " << avrg_duration << " (" << min_duration << "-" << max_duration << ")" << std::endl; + + for (unsigned int i = 0; i < T; ++i) { + clock_gettime(CLOCK_MONOTONIC, &start); + problem.calcDiff(xs, us); + clock_gettime(CLOCK_MONOTONIC, &finish); + elapsed = (finish.tv_sec - start.tv_sec)*1000000.0; + elapsed += (finish.tv_nsec - start.tv_nsec)/ 1000.0; + duration[i] = elapsed; //in us + } + + avrg_duration = duration.sum() / T; + min_duration = duration.minCoeff(); + max_duration = duration.maxCoeff(); + std::cout << "Wall time calcDiff [us]: " << avrg_duration << " (" << min_duration << "-" << max_duration << ")" << std::endl; } diff --git a/src/core/optctrl/shooting.cpp b/src/core/optctrl/shooting.cpp index bcf3417b83698756a6d025bebe01c6289191f14d..a7080835e2991d14a692fb1f5866447ef57131af 100644 --- a/src/core/optctrl/shooting.cpp +++ b/src/core/optctrl/shooting.cpp @@ -10,7 +10,7 @@ #include <iostream> #ifdef WITH_MULTITHREADING #include <omp.h> -#define NUM_THREADS 32 +#define NUM_THREADS 4 #endif //WITH_MULTITHREADING namespace crocoddyl {