timing.cpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl,
6  * KU Leuven. All rights reserved.
7  * Copyright (C) 2011-2014 Greg Horn
8  *
9  * CasADi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * CasADi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with CasADi; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 
26 #include "timing.hpp"
27 
28 namespace casadi {
29 
30  using namespace std::chrono;
32  }
33 
34  void FStats::reset() {
35  n_call = 0;
36  t_wall = 0;
37  t_proc = 0;
38  }
39 
40  void FStats::tic() {
41  start_proc = std::clock();
42  start_wall= high_resolution_clock::now();
43  }
44 
45  void FStats::toc() {
46  // First get the time points
47  stop_proc = std::clock();
48  stop_wall = high_resolution_clock::now();
49 
50  // Process them
51  double proc = static_cast<double>(stop_proc - start_proc) / static_cast<double>(CLOCKS_PER_SEC);
52  t_proc += proc;
53  double wall = duration<double>(stop_wall - start_wall).count();
54  t_wall += wall;
55  n_call +=1;
56 
57  }
58 
59  void FStats::join(FStats& rhs) {
60  t_proc += rhs.t_proc;
61  t_wall += rhs.t_wall;
62  n_call += rhs.n_call;
63  }
64 
66  f_.tic();
67  }
68 
70  f_.toc();
71  }
72 
73 } // namespace casadi
void reset()
Reset the statistics.
Definition: timing.cpp:34
void toc()
Stop timing.
Definition: timing.cpp:45
double t_wall
Accumulated wall time [s] since last reset.
Definition: timing.hpp:78
void join(FStats &rhs)
Definition: timing.cpp:59
double t_proc
Accumulated proc time [s] since last reset.
Definition: timing.hpp:81
void tic()
Start timing.
Definition: timing.cpp:40
casadi_int n_call
Accumulated number of calls since last reset.
Definition: timing.hpp:75
FStats()
Constructor.
Definition: timing.cpp:31
ScopedTiming(FStats &f)
Definition: timing.cpp:65
The casadi namespace.
Definition: archiver.cpp:28