Welcome to mirror list, hosted at ThFree Co, Russian Federation.

timer.cpp « base - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a789a57956a1c7405b12697358323d1f5a303552 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
#include "timer.hpp"

#include "../std/target_os.hpp"
#include "../std/time.hpp"
#include "../std/ctime.hpp"
#include "../std/stdint.hpp"

namespace my
{

Timer::Timer()
{
  Reset();
}

double Timer::LocalTime()
{
#ifdef OMIM_OS_WINDOWS
  FILETIME ft;
  GetSystemTimeAsFileTime(&ft);
  uint64_t val = ft.dwHighDateTime;
  val <<= 32;
  val += ft.dwLowDateTime;
  return val / 10000000.0;

#else
  timeval tv;
  gettimeofday(&tv, 0);
  return tv.tv_sec + tv.tv_usec / 1000000.0;
#endif
}

double Timer::ElapsedSeconds() const
{
  return LocalTime() - m_startTime;
}

void Timer::Reset()
{
  m_startTime = LocalTime();
}

string FormatCurrentTime()
{
    time_t t = time(NULL);
    string s = string(ctime(&t));

    for (size_t i = 0; i < s.size(); ++i)
      if (s[i] == ' ') s[i] = '_';

    s.erase(s.size() - 1, 1);
    return s;
}

}