sinc with TL rev. 38618.
[luatex.git] / source / libs / poppler / poppler-0.37.0 / goo / GooTimer.cc
blobc766c6bf2e4fe10fe042aba191713d191f6f972b
1 //========================================================================
2 //
3 // GooTimer.cc
4 //
5 // This file is licensed under GPLv2 or later
6 //
7 // Copyright 2005 Jonathan Blandford <jrb@redhat.com>
8 // Copyright 2007 Krzysztof Kowalczyk <kkowalczyk@gmail.com>
9 // Copyright 2010 Hib Eris <hib@hiberis.nl>
10 // Inspired by gtimer.c in glib, which is Copyright 2000 by the GLib Team
12 //========================================================================
14 #include <config.h>
16 #ifdef USE_GCC_PRAGMAS
17 #pragma implementation
18 #endif
20 #include "GooTimer.h"
21 #include <string.h>
23 #define USEC_PER_SEC 1000000
25 //------------------------------------------------------------------------
26 // GooTimer
27 //------------------------------------------------------------------------
29 GooTimer::GooTimer() {
30 start();
33 void GooTimer::start() {
34 #ifdef HAVE_GETTIMEOFDAY
35 gettimeofday(&start_time, NULL);
36 #elif defined(_WIN32)
37 QueryPerformanceCounter(&start_time);
38 #endif
39 active = true;
42 void GooTimer::stop() {
43 #ifdef HAVE_GETTIMEOFDAY
44 gettimeofday(&end_time, NULL);
45 #elif defined(_WIN32)
46 QueryPerformanceCounter(&end_time);
47 #endif
48 active = false;
51 #ifdef HAVE_GETTIMEOFDAY
52 double GooTimer::getElapsed()
54 double total;
55 struct timeval elapsed;
57 if (active)
58 gettimeofday(&end_time, NULL);
60 if (start_time.tv_usec > end_time.tv_usec) {
61 end_time.tv_usec += USEC_PER_SEC;
62 end_time.tv_sec--;
65 elapsed.tv_usec = end_time.tv_usec - start_time.tv_usec;
66 elapsed.tv_sec = end_time.tv_sec - start_time.tv_sec;
68 total = elapsed.tv_sec + ((double) elapsed.tv_usec / 1e6);
69 if (total < 0)
70 total = 0;
72 return total;
74 #elif defined(_WIN32)
75 double GooTimer::getElapsed()
77 LARGE_INTEGER freq;
78 double time_in_secs;
79 QueryPerformanceFrequency(&freq);
81 if (active)
82 QueryPerformanceCounter(&end_time);
84 time_in_secs = (double)(end_time.QuadPart-start_time.QuadPart)/(double)freq.QuadPart;
85 return time_in_secs * 1000.0;
88 #else
89 double GooTimer::getElapsed()
91 #warning "no support for GooTimer"
92 return 0;
94 #endif