We are going to win! wohoo

Dependencies:   mbed mbed-rtos

Committer:
xiaxia686
Date:
Wed Nov 14 15:51:56 2012 +0000
Revision:
4:698a3c538482
Parent:
1:6799c07fe510
removed varicance from sonar callback;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sv 1:6799c07fe510 1 /*
sv 1:6799c07fe510 2 * Tiny Vector Matrix Library
sv 1:6799c07fe510 3 * Dense Vector Matrix Libary of Tiny size using Expression Templates
sv 1:6799c07fe510 4 *
sv 1:6799c07fe510 5 * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net>
sv 1:6799c07fe510 6 *
sv 1:6799c07fe510 7 * This library is free software; you can redistribute it and/or
sv 1:6799c07fe510 8 * modify it under the terms of the GNU Lesser General Public
sv 1:6799c07fe510 9 * License as published by the Free Software Foundation; either
sv 1:6799c07fe510 10 * version 2.1 of the License, or (at your option) any later version.
sv 1:6799c07fe510 11 *
sv 1:6799c07fe510 12 * This library is distributed in the hope that it will be useful,
sv 1:6799c07fe510 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
sv 1:6799c07fe510 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
sv 1:6799c07fe510 15 * Lesser General Public License for more details.
sv 1:6799c07fe510 16 *
sv 1:6799c07fe510 17 * You should have received a copy of the GNU Lesser General Public
sv 1:6799c07fe510 18 * License along with this library; if not, write to the Free Software
sv 1:6799c07fe510 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
sv 1:6799c07fe510 20 *
sv 1:6799c07fe510 21 * $Id: Timer.h,v 1.9 2007-06-23 15:58:59 opetzold Exp $
sv 1:6799c07fe510 22 */
sv 1:6799c07fe510 23
sv 1:6799c07fe510 24 #ifndef TVMET_UTIL_TIMER_H
sv 1:6799c07fe510 25 #define TVMET_UTIL_TIMER_H
sv 1:6799c07fe510 26
sv 1:6799c07fe510 27 #if defined(TVMET_HAVE_SYS_TIME_H) && defined(TVMET_HAVE_UNISTD_H)
sv 1:6799c07fe510 28 # include <sys/time.h>
sv 1:6799c07fe510 29 # include <sys/resource.h>
sv 1:6799c07fe510 30 # include <unistd.h>
sv 1:6799c07fe510 31 #else
sv 1:6799c07fe510 32 # include <ctime>
sv 1:6799c07fe510 33 #endif
sv 1:6799c07fe510 34
sv 1:6799c07fe510 35 namespace tvmet {
sv 1:6799c07fe510 36
sv 1:6799c07fe510 37 namespace util {
sv 1:6799c07fe510 38
sv 1:6799c07fe510 39 /**
sv 1:6799c07fe510 40 \class Timer Timer.h "tvmet/util/Timer.h"
sv 1:6799c07fe510 41 \brief A quick& dirty portable timer, measures elapsed time.
sv 1:6799c07fe510 42
sv 1:6799c07fe510 43 It is recommended that implementations measure wall clock rather than CPU
sv 1:6799c07fe510 44 time since the intended use is performance measurement on systems where
sv 1:6799c07fe510 45 total elapsed time is more important than just process or CPU time.
sv 1:6799c07fe510 46
sv 1:6799c07fe510 47 The accuracy of timings depends on the accuracy of timing information
sv 1:6799c07fe510 48 provided by the underlying platform, and this varies from platform to
sv 1:6799c07fe510 49 platform.
sv 1:6799c07fe510 50 */
sv 1:6799c07fe510 51
sv 1:6799c07fe510 52 class Timer
sv 1:6799c07fe510 53 {
sv 1:6799c07fe510 54 Timer(const Timer&);
sv 1:6799c07fe510 55 Timer& operator=(const Timer&);
sv 1:6799c07fe510 56
sv 1:6799c07fe510 57 public: // types
sv 1:6799c07fe510 58 typedef double time_t;
sv 1:6799c07fe510 59
sv 1:6799c07fe510 60 public:
sv 1:6799c07fe510 61 /** starts the timer immediatly. */
sv 1:6799c07fe510 62 Timer() { m_start_time = getTime(); }
sv 1:6799c07fe510 63
sv 1:6799c07fe510 64 /** restarts the timer */
sv 1:6799c07fe510 65 void restart() { m_start_time = getTime(); }
sv 1:6799c07fe510 66
sv 1:6799c07fe510 67 /** return elapsed time in seconds */
sv 1:6799c07fe510 68 time_t elapsed() const { return (getTime() - m_start_time); }
sv 1:6799c07fe510 69
sv 1:6799c07fe510 70 private:
sv 1:6799c07fe510 71 time_t getTime() const {
sv 1:6799c07fe510 72 #if defined(TVMET_HAVE_SYS_TIME_H) && defined(TVMET_HAVE_UNISTD_H)
sv 1:6799c07fe510 73 getrusage(RUSAGE_SELF, &m_rusage);
sv 1:6799c07fe510 74 time_t sec = m_rusage.ru_utime.tv_sec; // user, no system time
sv 1:6799c07fe510 75 time_t usec = m_rusage.ru_utime.tv_usec; // user, no system time
sv 1:6799c07fe510 76 return sec + usec/1e6;
sv 1:6799c07fe510 77 #else
sv 1:6799c07fe510 78 return static_cast<time_t>(std::clock()) / static_cast<time_t>(CLOCKS_PER_SEC);
sv 1:6799c07fe510 79 #endif
sv 1:6799c07fe510 80 }
sv 1:6799c07fe510 81
sv 1:6799c07fe510 82 private:
sv 1:6799c07fe510 83 #if defined(TVMET_HAVE_SYS_TIME_H) && defined(TVMET_HAVE_UNISTD_H)
sv 1:6799c07fe510 84 mutable struct rusage m_rusage;
sv 1:6799c07fe510 85 #endif
sv 1:6799c07fe510 86 time_t m_start_time;
sv 1:6799c07fe510 87 };
sv 1:6799c07fe510 88
sv 1:6799c07fe510 89 } // namespace util
sv 1:6799c07fe510 90
sv 1:6799c07fe510 91 } // namespace tvmet
sv 1:6799c07fe510 92
sv 1:6799c07fe510 93 #endif // TVMET_UTIL_TIMER_H
sv 1:6799c07fe510 94
sv 1:6799c07fe510 95 // Local Variables:
sv 1:6799c07fe510 96 // mode:C++
sv 1:6799c07fe510 97 // tab-width:8
sv 1:6799c07fe510 98 // End: