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

Last change on this file since 2 was 2, checked in by Eugene Romanenko, 16 years ago

First import

File size: 1.2 KB
Line 
1//========================================================================
2//
3// GooTimer.cc
4//
5// Copyright 2005 Jonathan Blandford <jrb@redhat.com>
6// Inspired by gtimer.c in glib, which is Copyright 2000 by the GLib Team
7//
8//========================================================================
9
10#include <config.h>
11
12#ifdef HAVE_GETTIMEOFDAY
13
14#ifdef USE_GCC_PRAGMAS
15#pragma implementation
16#endif
17
18#include <string.h>
19#include "GooTimer.h"
20
21//------------------------------------------------------------------------
22// GooTimer
23//------------------------------------------------------------------------
24
25
26GooTimer::GooTimer() {
27  gettimeofday (&start, NULL);
28  active = true;
29}
30
31
32void
33GooTimer::stop() {
34  gettimeofday (&end, NULL);
35  active = false;
36}
37
38#define USEC_PER_SEC 1000000
39double
40GooTimer::getElapsed ()
41{
42  double total;
43  struct timeval elapsed;
44
45  if (active)
46    gettimeofday (&end, NULL);
47
48  if (start.tv_usec > end.tv_usec)
49    {
50      end.tv_usec += USEC_PER_SEC;
51      end.tv_sec--;
52    }
53
54  elapsed.tv_usec = end.tv_usec - start.tv_usec;
55  elapsed.tv_sec = end.tv_sec - start.tv_sec;
56
57  total = elapsed.tv_sec + ((double) elapsed.tv_usec / 1e6);
58  if (total < 0)
59    {
60      total = 0;
61    }
62
63  return total;
64}
65
66#endif
Note: See TracBrowser for help on using the repository browser.