Bsoft  2.1.0
Bernard's software package
timer.cpp
Go to the documentation of this file.
1 
9 #include <ctime>
10 #include <sys/time.h>
11 //#include <chrono>
12 
13 #include "timer.h"
14 #include "utilities.h"
15 
16 // Declaration of global variables
17 extern int verbose; // Level of output to the screen
18 
26 double getwalltime()
27 {
28  timeval thetime;
29 
30  gettimeofday(&thetime, NULL);
31 
32  return (double) (thetime.tv_sec + 1e-6L*thetime.tv_usec);
33 }
34 /*
35 double getwalltime()
36 {
37  return chrono::system_clock::now();
38 }
39 */
40 
49 double getcputime()
50 {
51  clock_t thetime = clock();
52 
53  return (double) (thetime/CLOCKS_PER_SEC);
54 }
55 
61 double timer_start()
62 {
63  double thetime = getwalltime();
64 
65  if ( verbose & VERB_DEBUG )
66  cout << "DEBUG timer_start: time = " << thetime << endl;
67 
68  return thetime;
69 }
70 
76 double timer_report(double lasttime)
77 {
78  double difftime = getwalltime() - lasttime;
79 
80  if ( verbose & VERB_DEBUG )
81  cout << "DEBUG timer_report: lasttime = " << difftime << endl;
82 
83  if ( verbose & VERB_TIME )
84  cout << "Time elapsed: " << difftime << " s" << endl;
85 
86  return difftime;
87 }
88 
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
timer.h
Utilities for timing functions.
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:61
VERB_TIME
#define VERB_TIME
Definition: utilities.h:114
utilities.h
Header file for general utilities.
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:76
getcputime
double getcputime()
Returns the clock time.
Definition: timer.cpp:49
getwalltime
double getwalltime()
Returns the current time.
Definition: timer.cpp:26
verbose
int verbose