benchmark.cpp 1.85 KB
Newer Older
1
2
3
4
5
6
7
8
#ifndef BENCHMARK
#define BENCHMARK

#include "./model/Helper.h"
#include "./model/de_rwth_armin_modeling_autopilot_motion_motionPlanning.h"
#include <iostream>
#include <chrono>

9
10
void execute(de_rwth_armin_modeling_autopilot_motion_motionPlanning&, double&, double&);

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// https://stackoverflow.com/a/19471595/1432357
class Timer
{
public:
    Timer() : beg_(clock_::now()) {}
    void reset() { beg_ = clock_::now(); }
    double elapsed() const {
        return std::chrono::duration_cast<second_>
            (clock_::now() - beg_).count(); }

private:
    typedef std::chrono::high_resolution_clock clock_;
    typedef std::chrono::duration<double, std::ratio<1> > second_;
    std::chrono::time_point<clock_> beg_;
};

int main () {
  std::cout << "initialization...\n";
  Helper::init();
  de_rwth_armin_modeling_autopilot_motion_motionPlanning motionPlanning;
  motionPlanning.init();
  const int N = 1000000;
Alexander Ryndin's avatar
Alexander Ryndin committed
33
34
  double _currentDirectionX = 0.0;
  double _desiredDirectionX = 1.0;
35
36
  // warm up, load DLLs if needed
  execute(motionPlanning, _currentDirectionX, _desiredDirectionX);
37
38
39
  std::cout << "running benchmark\n";
  Timer tmr;
  for (int i=0; i<N; i++) {
40
    execute(motionPlanning, _currentDirectionX, _desiredDirectionX);
41
42
43
44
45
46
47
  }
  double t = tmr.elapsed();
  double avgDuration = t / N;
  std::cout << "avgDuration = " << avgDuration << " sec\n";
  return 0;
}

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
void execute(de_rwth_armin_modeling_autopilot_motion_motionPlanning& cmp,
        double& _currentDirectionX,
        double& _desiredDirectionX) {
    cmp.currentDirectionX = _currentDirectionX;
    cmp.currentDirectionY = 1.0;
    cmp.desiredDirectionX = _desiredDirectionX;
    cmp.desiredDirectionY = 1.0;
    cmp.signedDistanceToTrajectory = 0.15;
    cmp.currentVelocity = 10.0;
    cmp.desiredVelocity = 11.0;
    cmp.execute();
    _currentDirectionX = cmp.steering;
    _desiredDirectionX = cmp.brakes;
}

63
#endif