-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_timer.cpp
More file actions
44 lines (35 loc) · 1.02 KB
/
function_timer.cpp
File metadata and controls
44 lines (35 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
*
* @file function_timer.cpp
* @author Thomas R. Carrel
*
* @brief Defines the Function_Timer class.
*
*/
#include "function_timer.h"
/** Ctor.
* @param f The function name, used in the output when the destructor is
* called, the timer is started after the string is copied so that its affect
* on a function's runtime is minimal.
* @param file The file or stream to output to.
*/
Function_Timer::Function_Timer( const std::string& f, FILE* file ) :
print_to_( file ),
message_(f),
start_( std::chrono::high_resolution_clock::now() )
{}
/** Dtor.
* Calculates the time elapsed since the object was created and outputs the
* time to stderr.
*/
Function_Timer::~Function_Timer( void )
{
std::chrono::duration<long double> time =
std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::high_resolution_clock::now() - start_ );
fprintf(
print_to_,
"%s took %.15Lf seconds.\n",
message_.c_str(),
time.count() );
}