Tapkee
time.hpp
Go to the documentation of this file.
1 /* This software is distributed under BSD 3-clause license (see LICENSE file).
2  *
3  * Copyright (c) 2012-2013 Sergey Lisitsyn
4  */
5 
6 #ifndef TAPKEE_TIME_H_
7 #define TAPKEE_TIME_H_
8 
9 /* Tapkee includes */
10 #include <tapkee/utils/logging.hpp>
11 /* End of Tapkee includes */
12 
13 #include <ctime>
14 #include <string>
15 #include <sstream>
16 
17 namespace tapkee
18 {
19 namespace tapkee_internal
20 {
21 #ifdef _OPENMP
22  #define CLOCK_TYPE double
23  #define CLOCK_GET omp_get_wtime()
24  #define CLOCK_DIVISOR 1
25 #else
26  #define CLOCK_TYPE clock_t
27  #define CLOCK_GET clock()
28  #define CLOCK_DIVISOR CLOCKS_PER_SEC
29 #endif
30 
32 {
34  std::string operation_name;
35  timed_context(const std::string& name) : start_clock(CLOCK_GET), operation_name(name)
36  {
37  }
39  {
40  std::string message = formatting::format("{} took {} seconds.", operation_name,
43  }
44 };
45 }
46 }
47 
48 #undef CLOCK_TYPE
49 #undef CLOCK_GET
50 #undef CLOCK_DIVISOR
51 
52 #endif
void message_benchmark(const std::string &msg)
Definition: logging.hpp:119
#define CLOCK_TYPE
Definition: time.hpp:26
std::string format(const std::string &fmt, const ValueWrapper a)
Definition: formatting.hpp:411
#define CLOCK_DIVISOR
Definition: time.hpp:28
timed_context(const std::string &name)
Definition: time.hpp:35
#define CLOCK_GET
Definition: time.hpp:27
static LoggingSingleton & instance()
Definition: logging.hpp:102