source: trunk/poppler/mypoppler/goo/GooTimer.cc @ 461

Last change on this file since 461 was 461, checked in by Silvan Scherrer, 11 years ago

poppler update to 0.14.2

File size: 2.0 KB
Line 
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
11//
12//========================================================================
13
14#include <config.h>
15
16#ifdef USE_GCC_PRAGMAS
17#pragma implementation
18#endif
19
20#include "GooTimer.h"
21#include <string.h>
22
23#define USEC_PER_SEC 1000000
24
25//------------------------------------------------------------------------
26// GooTimer
27//------------------------------------------------------------------------
28
29GooTimer::GooTimer() {
30  start();
31}
32
33void GooTimer::start() {
34#ifdef HAVE_GETTIMEOFDAY
35  gettimeofday(&start_time, NULL);
36#elif defined(_WIN32)
37  QueryPerformanceCounter(&start_time);
38#endif
39  active = true;
40}
41
42void GooTimer::stop() {
43#ifdef HAVE_GETTIMEOFDAY
44  gettimeofday(&end_time, NULL);
45#elif defined(_WIN32)
46  QueryPerformanceCounter(&end_time);
47#endif
48  active = false;
49}
50
51#ifdef HAVE_GETTIMEOFDAY
52double GooTimer::getElapsed()
53{
54  double total;
55  struct timeval elapsed;
56
57  if (active)
58    gettimeofday(&end_time, NULL);
59
60  if (start_time.tv_usec > end_time.tv_usec) {
61      end_time.tv_usec += USEC_PER_SEC;
62      end_time.tv_sec--;
63  }
64
65  elapsed.tv_usec = end_time.tv_usec - start_time.tv_usec;
66  elapsed.tv_sec = end_time.tv_sec - start_time.tv_sec;
67
68  total = elapsed.tv_sec + ((double) elapsed.tv_usec / 1e6);
69  if (total < 0)
70      total = 0;
71
72  return total;
73}
74#elif defined(_WIN32)
75double GooTimer::getElapsed()
76{
77  LARGE_INTEGER   freq;
78  double          time_in_secs;
79  QueryPerformanceFrequency(&freq);
80
81  if (active)
82    QueryPerformanceCounter(&end_time);
83
84  time_in_secs = (double)(end_time.QuadPart-start_time.QuadPart)/(double)freq.QuadPart;
85  return time_in_secs * 1000.0;
86
87}
88#else
89double GooTimer::getElapsed()
90{
91#warning "no support for GooTimer"
92  return 0;
93}
94#endif
95
Note: See TracBrowser for help on using the repository browser.