| Bsoft 2.0.5 Bernard's software package

timer.cpp
Go to the documentation of this file.
1
9 #include "timer.h"
10 #include "utilities.h"
11
12 // Declaration of global variables
13 extern int verbose; // Level of output to the screen
14
23 double getwalltime()
24 {
25 timeval thetime;
26
27 gettimeofday(&thetime, NULL);
28
29 return (double) (thetime.tv_sec + 1e-6L*thetime.tv_usec);
30 }
31
40 double getcputime()
41 {
42 clock_t thetime = clock();
43
44 return (double) (thetime/CLOCKS_PER_SEC);
45 }
46
52 double timer_start()
53 {
54 double thetime = getwalltime();
55
56 if ( verbose & VERB_DEBUG )
57 cout << "DEBUG timer_start: time = " << thetime << endl;
58
59 return thetime;
60 }
61
67 double timer_report(double lasttime)
68 {
69 double difftime = getwalltime() - lasttime;
70
71 if ( verbose & VERB_DEBUG )
72 cout << "DEBUG timer_report: lasttime = " << difftime << endl;
73
74 if ( verbose & VERB_TIME )
75 cout << "Time elapsed: " << difftime << " s" << endl;
76
77 return difftime;
78 }
79
getwalltime
double getwalltime()
Returns the current time.
Definition: timer.cpp:23
utilities.h
Header file for general utilities.
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:112
verbose
int verbose
timer.h
Utilities for timing functions.
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
getcputime
double getcputime()
Returns the clock time.
Definition: timer.cpp:40