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