MClock.h
1 /* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2  * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3  * Author(s): David Salinas
4  *
5  * Copyright (C) 2014 Inria
6  *
7  * Modification(s):
8  * - YYYY/MM Author: Description of the modification
9  */
10 
11 #ifndef UTILS_MCLOCK_H_
12 #define UTILS_MCLOCK_H_
13 
14 #include <sys/time.h>
15 
16 class MClock {
17  public:
18  MClock() {
19  end_called = false;
20  begin();
21  }
22 
23  void begin() const {
24  end_called = false;
25  gettimeofday(&startTime, NULL);
26  }
27 
28  void end() const {
29  end_called = true;
30  gettimeofday(&endTime, NULL);
31  }
32 
33  friend std::ostream& operator<<(std::ostream& stream, const MClock& clock) {
34  // if(!clock.end_called) clock.end();
35  if (!clock.end_called) {
36  stream << "end not called";
37  } else {
38  long totalTime = (clock.endTime.tv_sec - clock.startTime.tv_sec) * 1000000L;
39  totalTime += (clock.endTime.tv_usec - clock.startTime.tv_usec);
40  stream << clock.num_seconds() << "s";
41  }
42  return stream;
43  }
44 
45  double num_seconds() const {
46  if (!end_called) end();
47  long totalTime = (endTime.tv_sec - startTime.tv_sec) * 1000000L;
48  totalTime += (endTime.tv_usec - startTime.tv_usec);
49  return (totalTime / 1000L) / static_cast<double>(1000);
50  }
51 
52  private:
53  mutable struct timeval startTime, endTime;
54  mutable bool end_called;
55 };
56 
57 #endif // UTILS_MCLOCK_H_
std::ostream & operator<<(std::ostream &os, const Permutahedral_representation< Vertex, OrderedSetPartition > &simplex)
Print a permutahedral representation to a stream.
Definition: Permutahedral_representation.h:173
GUDHIdev  Version 3.5.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : MIT Generated on Tue Aug 16 2022 14:01:50 for GUDHIdev by Doxygen 1.9.1