cprover
time_stopping.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Time Stopping
4 
5 Author: Daniel Kroening
6 
7 Date: February 2004
8 
9 \*******************************************************************/
10 
13 
14 #include "time_stopping.h"
15 
16 #include <sstream>
17 
18 #if defined(_WIN32) && !defined(__MINGW32__)
19 #include <windows.h>
20 #include <winbase.h>
21 #else
22 #include <sys/time.h>
23 #endif
24 
25 #if defined(_WIN32) && !defined(__MINGW32__)
26 // NOLINTNEXTLINE(readability/identifiers)
27 struct timezone
28 {
29  int dummy;
30 };
31 
32 // NOLINTNEXTLINE(readability/identifiers)
33 void gettimeofday(struct timeval* p, struct timezone *tz)
34 {
35  union
36  {
37  long long ns100; /*time since 1 Jan 1601 in 100ns units */
38  FILETIME ft;
39  } _now;
40 
41  GetSystemTimeAsFileTime(&(_now.ft));
42  p->tv_usec=(long)((_now.ns100 / 10LL) % 1000000LL);
43  p->tv_sec= (long)((_now.ns100-(116444736000000000LL))/10000000LL);
44 }
45 #endif
46 
48 {
49  // NOLINTNEXTLINE(readability/identifiers)
50  struct timeval tv;
51  // NOLINTNEXTLINE(readability/identifiers)
52  struct timezone tz;
53 
54  gettimeofday(&tv, &tz);
55 
56  return absolute_timet(tv.tv_usec/1000+(unsigned long long)tv.tv_sec*1000);
57 }
58 
59 std::ostream &operator << (std::ostream &out, const time_periodt &period)
60 {
61  return out << static_cast<double>(period.get_t())/1000;
62 }
63 
64 std::string time_periodt::as_string() const
65 {
66  std::ostringstream out;
67  out << *this;
68  return out.str();
69 }
std::string as_string() const
std::ostream & operator<<(std::ostream &out, const time_periodt &period)
unsigned long long get_t() const
Definition: time_stopping.h:31
Time Stopping.
absolute_timet current_time()