GENIE
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Timing.cc
Go to the documentation of this file.
1 
5 #include <sys/time.h>
6 #include <stdlib.h>
7 #include "Timing.h"
8 
9 // Get current date/time, format is YYYY-MM-DD.HH:mm:ss
11  time_t now = time(0);
12  struct tm tstruct;
13  char buf[80];
14  tstruct = *localtime(&now);
15  // Visit http://en.cppreference.com/w/cpp/chrono/c/strftime
16  // for more information about date/time format
17  strftime(buf, sizeof(buf), "%Y-%m-%d-%X", &tstruct);
18 
19  return buf;
20 }
21 
22 unsigned long long genie::utility::getTime()
23 {
24  struct timeval tv;
25 
26  gettimeofday(&tv, NULL);
27 
28  unsigned long long ret = tv.tv_usec;
29 
30  /* Adds the seconds after converting them to microseconds (10^-6) */
31  ret += (tv.tv_sec * 1000 * 1000);
32 
33  return ret;
34 }
35 
36 double genie::utility::getInterval(unsigned long long start, unsigned long long stop)
37 {
38  return (double) (stop - start) / 1000.0;
39 }
unsigned long long getTime()
Get system time.
Definition: Timing.cc:22
std::string currentDateTime()
Get current data time.
Definition: Timing.cc:10
double getInterval(unsigned long long start, unsigned long long stop)
Calculate time interval from start to end.
Definition: Timing.cc:36
Functions about getting system time.