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

Last change on this file since 257 was 257, checked in by Eugene Romanenko, 13 years ago

PDF plugin: Poppler library updated to version 0.10.0

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