blob: cbbea1c5ff5458eee6aea5e1674ac93bdba44330 (
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
/************************************************************************
Routines for measuring time.
$Id: time.cxx 427 2004-09-27 04:45:31Z garland $
************************************************************************/
#include <gfx/gfx.h>
#if defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
namespace gfx
{
// Only Windows NT supports getting proper time usage information.
// In Windows 95, we have to settle for measuring real time.
double get_cpu_time()
{
FILETIME start, end, kernel, user;
if( !GetThreadTimes(GetCurrentThread(), &start, &end, &kernel, &user) )
{
// We're running under Windows 95 instead of NT.
// Just get the current time and be done with it.
SYSTEMTIME now;
GetSystemTime(&now);
SystemTimeToFileTime(&now, &user);
}
// Convert into something we can do math on
LARGE_INTEGER i;
i.LowPart = user.dwLowDateTime;
i.HighPart = user.dwHighDateTime;
#ifdef __GNUC__
// The Win32 headers shipped with GCC don't define the QuadPart
// accessor for the LARGE_INTEGER type. So we have to build it
// directly.
long long quad = i.HighPart;
quad = (quad << 32) + i.LowPart;
return (double)quad / 1e7;
#else
// Convert to seconds and return
return (double)(i.QuadPart) / 1e7;
#endif
}
}
#elif defined(HAVE_GETRUSAGE)
#include <sys/time.h>
#include <sys/resource.h>
namespace gfx
{
double get_cpu_time()
{
struct rusage t;
getrusage(RUSAGE_SELF, &t);
return (double)t.ru_utime.tv_sec + (double)t.ru_utime.tv_usec/1000000;
}
}
#elif defined(HAVE_TIMES)
namespace gfx
{
double get_cpu_time()
{
struct tms t;
times(&t);
return (double)(t.tms_utime) / (double)CLK_TCK;
}
}
#else
#error "No supported timing mechanism available."
#endif
|