]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | ********************************************************************** | |
374ca955 | 3 | * Copyright (c) 2002-2004, International Business Machines |
b75a7d8f A |
4 | * Corporation and others. All Rights Reserved. |
5 | ********************************************************************** | |
b75a7d8f A |
6 | * 2002-09-20 aliu Created. |
7 | */ | |
8 | #ifndef __PERFTIMER_H__ | |
9 | #define __PERFTIMER_H__ | |
10 | ||
11 | #include "unicode/utypes.h" | |
12 | ||
13 | // Derived from Ram's perftime.h | |
14 | ||
15 | //---------------------------------------------------------------------- | |
16 | // Win32 | |
17 | ||
18 | #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) | |
19 | ||
20 | #include <windows.h> | |
21 | ||
22 | class Timer { | |
23 | LARGE_INTEGER tstart, tend; | |
24 | public: | |
25 | Timer() {} | |
26 | inline void start() { | |
27 | QueryPerformanceCounter(&tstart); | |
28 | } | |
29 | inline double stop() { | |
30 | QueryPerformanceCounter(&tend); | |
31 | LARGE_INTEGER freq; | |
32 | int result = QueryPerformanceFrequency(&freq); | |
33 | return ((double)(tend.QuadPart - tstart.QuadPart))/((double)freq.QuadPart); | |
34 | } | |
35 | }; | |
36 | ||
37 | //---------------------------------------------------------------------- | |
38 | // UNIX | |
39 | ||
40 | #else | |
41 | ||
42 | #include <sys/time.h> | |
43 | ||
44 | class Timer { | |
45 | struct timeval tstart, tend; | |
46 | struct timezone tz; | |
47 | public: | |
48 | Timer() {} | |
49 | inline void start() { | |
50 | gettimeofday(&tstart, &tz); | |
51 | } | |
52 | inline double stop() { | |
53 | gettimeofday(&tend, &tz); | |
54 | double t1, t2; | |
55 | t1 = (double)tstart.tv_sec + (double)tstart.tv_usec*1e-6; | |
56 | t2 = (double)tend.tv_sec + (double)tend.tv_usec*1e-6; | |
57 | return t2-t1; | |
58 | } | |
59 | }; | |
60 | ||
61 | #endif | |
62 | #endif |