00001 // 00002 // Copyright (c) 2006-2012, Benjamin Kaufmann 00003 // 00004 // This file is part of Clasp. See http://www.cs.uni-potsdam.de/clasp/ 00005 // 00006 // Clasp is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation; either version 2 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // Clasp is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with Clasp; if not, write to the Free Software 00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00019 // 00020 00021 #ifndef CLASP_TIMER_H_INCLUDED 00022 #define CLASP_TIMER_H_INCLUDED 00023 00024 #ifdef _MSC_VER 00025 #pragma once 00026 #endif 00027 00028 namespace Clasp { 00029 00030 struct ProcessTime { 00031 static double getTime(); 00032 }; 00033 00034 struct ThreadTime { 00035 static double getTime(); 00036 }; 00037 00038 struct RealTime { 00039 static double getTime(); 00040 }; 00041 00042 template <class TimeType> 00043 class Timer { 00044 public: 00045 Timer() : start_(0), split_(0), total_(0) {} 00046 00047 void start() { start_ = TimeType::getTime(); } 00048 void stop() { split(TimeType::getTime()); } 00049 void reset() { *this = Timer(); } 00051 void lap() { double t; split(t = TimeType::getTime()); start_ = t; } 00053 double elapsed() const { return split_; } 00055 double total() const { return total_; } 00056 private: 00057 void split(double t) { total_ += (split_ = t-start_); } 00058 double start_; 00059 double split_; 00060 double total_; 00061 }; 00062 00063 } 00064 #endif