ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
timer.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
11 #include <admodel.h>
12 #if !defined(_WIN32)
13 #include <sys/time.h>
14 #include <iostream>
15 
20 {
21  gettimeofday(&tv,0);
22 
23  tvold.tv_sec=tv.tv_sec;
24  tvold.tv_usec=tv.tv_usec;
25 }
26 
32 {
33  long int nsec=0;
34  long int nusec=0;
35  gettimeofday(&tv,0);
36  if ( tv.tv_usec< tvold.tv_usec)
37  {
38  nsec=tv.tv_sec-tvold.tv_sec-1;
39  nusec=tv.tv_usec-tvold.tv_usec+1000000;
40  }
41  else
42  {
43  nsec=tv.tv_sec-tvold.tv_sec;
44  nusec=tv.tv_usec-tvold.tv_usec;
45  }
46 
47  //reset
48  tvold.tv_sec=tv.tv_sec;
49  tvold.tv_usec=tv.tv_usec;
50 
51  return 1000.0 * (double)nsec + 0.001 * (double)nusec;
52 }
53 
58 {
59  long int nsec=0;
60  long int nusec=0;
61  gettimeofday(&tv,0);
62  if ( tv.tv_usec< tvold.tv_usec)
63  {
64  nsec=tv.tv_sec-tvold.tv_sec-1;
65  nusec=tv.tv_usec-tvold.tv_usec+1000000;
66  }
67  else
68  {
69  nsec=tv.tv_sec-tvold.tv_sec;
70  nusec=tv.tv_usec-tvold.tv_usec;
71  }
72  return 1000.0 * (double)nsec + 0.001 * (double)nusec;
73 }
74 
75 #else
76 #include <windows.h>
77 
82 {
83 #if defined(_MSC_VER)
84  t=GetTickCount64();
85 #else
86  t=GetCurrentTime();
87 #endif
88  told=t;
89 }
90 
96 {
97  double diff = get_elapsed_time();
98  told = t;
99  return diff;
100 }
101 
107 {
108 #if defined(_MSC_VER)
109  t=GetTickCount64();
110  unsigned long long diff = t - told;
111 #else
112  t=GetCurrentTime();
113  DWORD diff = t - told;
114 #endif
115  return static_cast<double>(diff);
116 }
117 #endif
double get_elapsed_time(void)
Returns the elapsed time in milliseconds from the timer object.
Definition: timer.cpp:57
timeval tv
Definition: fvar.hpp:8903
timeval tvold
Definition: fvar.hpp:8904
double get_elapsed_time_and_reset(void)
Returns elapsed time in milliseconds of timer object and then resets the timer to current time...
Definition: timer.cpp:31
Description not yet available.
adtimer(void)
Default constructor.
Definition: timer.cpp:19