2 Copyright (C) 1998, 1999, 2000, 2007 John Anderson
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 millisecond timer class.
39 start the timer running if true, or just create the
42 Timer( bool shouldStart = true )
49 Start the timer running. Return the current timestamp, in milliseconds
54 _start = (unsigned long)::GetTickCount();
56 gettimeofday ( &_start, 0 );
62 return ( _start.tv_sec * 1000000 + _start.tv_usec ) / 1000;
67 returns the number of milliseconds since start
68 also stops the timer running
73 _stop = (unsigned long)::GetTickCount();
75 gettimeofday ( &_stop, 0 );
82 returns the number of milliseconds since start
84 unsigned long elapsed() const
89 DWORD current = ::GetTickCount();
90 return current - _start;
92 struct timeval current;
93 gettimeofday ( ¤t, 0 );
95 ( current.tv_sec * 1000000 + current.tv_usec ) - ( _start.tv_sec * 1000000 + _start.tv_usec )
103 return _stop - _start;
106 ( _stop.tv_sec * 1000000 + _stop.tv_usec ) - ( _start.tv_sec * 1000000 + _start.tv_usec )
114 Call stop and then start. Return the value from stop.
116 unsigned long restart()
118 unsigned long retval = stop();
125 unsigned long _start;
128 struct timeval _start;
129 struct timeval _stop;