Tapkee
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
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
31
struct
timed_context
32
{
33
CLOCK_TYPE
start_clock
;
34
std::string
operation_name
;
35
timed_context
(
const
std::string& name) :
start_clock
(
CLOCK_GET
),
operation_name
(name)
36
{
37
}
38
~timed_context
()
39
{
40
std::stringstream msg_stream;
41
msg_stream <<
operation_name
<<
" took "
<< double(
CLOCK_GET
-
start_clock
)/
CLOCK_DIVISOR
<<
" seconds."
;
42
LoggingSingleton::instance
().
message_benchmark
(msg_stream.str());
43
}
44
};
45
}
46
}
47
48
#undef CLOCK_TYPE
49
#undef CLOCK_GET
50
#undef CLOCK_DIVISOR
51
52
#endif
tapkee::LoggingSingleton::message_benchmark
void message_benchmark(const std::string &msg)
Definition:
logging.hpp:117
tapkee::tapkee_internal::timed_context::~timed_context
~timed_context()
Definition:
time.hpp:38
tapkee::tapkee_internal::timed_context::operation_name
std::string operation_name
Definition:
time.hpp:34
CLOCK_TYPE
#define CLOCK_TYPE
Definition:
time.hpp:26
tapkee::tapkee_internal::timed_context
Definition:
time.hpp:31
CLOCK_DIVISOR
#define CLOCK_DIVISOR
Definition:
time.hpp:28
tapkee::tapkee_internal::timed_context::start_clock
clock_t start_clock
Definition:
time.hpp:33
tapkee::tapkee_internal::timed_context::timed_context
timed_context(const std::string &name)
Definition:
time.hpp:35
CLOCK_GET
#define CLOCK_GET
Definition:
time.hpp:27
logging.hpp
tapkee::LoggingSingleton::instance
static LoggingSingleton & instance()
Definition:
logging.hpp:100
include
tapkee
utils
time.hpp
Generated by
1.8.5