[Lemon-commits] Alpar Juttner: Merge
Lemon HG
hg at lemon.cs.elte.hu
Sat Apr 12 20:44:17 CEST 2008
details: http://lemon.cs.elte.hu/hg/lemon/rev/35840c5aa696
changeset: 122:35840c5aa696
user: Alpar Juttner <alpar [at] cs.elte.hu>
date: Sat Apr 12 19:42:38 2008 +0100
description:
Merge
diffstat:
6 files changed, 857 insertions(+)
lemon/Makefile.am | 2
lemon/counter.h | 181 +++++++++++++++
lemon/time_measure.h | 541 +++++++++++++++++++++++++++++++++++++++++++++
test/Makefile.am | 4
test/counter_test.cc | 66 +++++
test/time_measure_test.cc | 63 +++++
diffs (truncated from 918 to 300 lines):
diff -r 407c08a0eae9 -r 35840c5aa696 lemon/Makefile.am
--- a/lemon/Makefile.am Fri Apr 11 16:20:54 2008 +0200
+++ b/lemon/Makefile.am Sat Apr 12 19:42:38 2008 +0100
@@ -20,6 +20,7 @@
lemon/assert.h \
lemon/bfs.h \
lemon/bin_heap.h \
+ lemon/counter.h \
lemon/dfs.h \
lemon/dijkstra.h \
lemon/dim2.h \
@@ -32,6 +33,7 @@
lemon/path.h \
lemon/random.h \
lemon/smart_graph.h \
+ lemon/time_measure.h \
lemon/tolerance.h \
lemon/unionfind.h
diff -r 407c08a0eae9 -r 35840c5aa696 lemon/counter.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lemon/counter.h Sat Apr 12 19:42:38 2008 +0100
@@ -0,0 +1,181 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2008
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_COUNTER_H
+#define LEMON_COUNTER_H
+
+#include <string>
+#include <iostream>
+
+///\ingroup timecount
+///\file
+///\brief Tools for counting steps and events
+
+namespace lemon
+{
+
+ template<class P> class _NoSubCounter;
+
+ template<class P>
+ class _SubCounter
+ {
+ P &_parent;
+ std::string _title;
+ std::ostream &_os;
+ int count;
+ public:
+
+ typedef _SubCounter<_SubCounter<P> > SubCounter;
+ typedef _NoSubCounter<_SubCounter<P> > NoSubCounter;
+
+ _SubCounter(P &parent)
+ : _parent(parent), _title(), _os(std::cerr), count(0) {}
+ _SubCounter(P &parent,std::string title,std::ostream &os=std::cerr)
+ : _parent(parent), _title(title), _os(os), count(0) {}
+ _SubCounter(P &parent,const char *title,std::ostream &os=std::cerr)
+ : _parent(parent), _title(title), _os(os), count(0) {}
+ ~_SubCounter() {
+ _os << _title << count <<std::endl;
+ _parent+=count;
+ }
+ _SubCounter &operator++() { count++; return *this;}
+ int operator++(int) { return count++; }
+ _SubCounter &operator--() { count--; return *this;}
+ int operator--(int) { return count--; }
+ _SubCounter &operator+=(int c) { count+=c; return *this;}
+ _SubCounter &operator-=(int c) { count-=c; return *this;}
+ void reset(int c=0) {count=c;}
+ operator int() {return count;}
+ };
+
+ template<class P>
+ class _NoSubCounter
+ {
+ P &_parent;
+ public:
+ typedef _NoSubCounter<_NoSubCounter<P> > SubCounter;
+ typedef _NoSubCounter<_NoSubCounter<P> > NoSubCounter;
+
+ _NoSubCounter(P &parent) :_parent(parent) {}
+ _NoSubCounter(P &parent,std::string,std::ostream &)
+ :_parent(parent) {}
+ _NoSubCounter(P &parent,std::string)
+ :_parent(parent) {}
+ _NoSubCounter(P &parent,const char *,std::ostream &)
+ :_parent(parent) {}
+ _NoSubCounter(P &parent,const char *)
+ :_parent(parent) {}
+ ~_NoSubCounter() {}
+ _NoSubCounter &operator++() { ++_parent; return *this;}
+ int operator++(int) { _parent++; return 0;}
+ _NoSubCounter &operator--() { --_parent; return *this;}
+ int operator--(int) { _parent--; return 0;}
+ _NoSubCounter &operator+=(int c) { _parent+=c; return *this;}
+ _NoSubCounter &operator-=(int c) { _parent-=c; return *this;}
+ void reset(int) {}
+ void reset() {}
+ operator int() {return 0;}
+ };
+
+
+ /// \addtogroup timecount
+ /// @{
+
+ ///A counter class
+
+ ///This class makes it easier to count certain events. You can increment
+ ///or decrement the counter using operator++ and operator--.
+ ///A report is automatically printed on destruction.
+ ///\todo More doc
+ class Counter
+ {
+ std::string _title;
+ std::ostream &_os;
+ int count;
+ public:
+ ///\e
+
+ ///\todo document please.
+ ///
+ typedef _SubCounter<Counter> SubCounter;
+ ///\e
+
+ ///\todo document please.
+ ///
+ typedef _NoSubCounter<Counter> NoSubCounter;
+
+ ///\e
+ Counter() : _title(), _os(std::cerr), count(0) {}
+ ///\e
+ Counter(std::string title,std::ostream &os=std::cerr)
+ : _title(title), _os(os), count(0) {}
+ ///\e
+ Counter(const char *title,std::ostream &os=std::cerr)
+ : _title(title), _os(os), count(0) {}
+ ///Destructor. Prints the given title and the value of the counter.
+ ~Counter() {
+ _os << _title << count <<std::endl;
+ }
+ ///\e
+ Counter &operator++() { count++; return *this;}
+ ///\e
+ int operator++(int) { return count++;}
+ ///\e
+ Counter &operator--() { count--; return *this;}
+ ///\e
+ int operator--(int) { return count--;}
+ ///\e
+ Counter &operator+=(int c) { count+=c; return *this;}
+ ///\e
+ Counter &operator-=(int c) { count-=c; return *this;}
+ ///\e
+ void reset(int c=0) {count=c;}
+ ///\e
+ operator int() {return count;}
+ };
+
+ ///'Do nothing' version of \ref Counter
+
+ ///'Do nothing' version of \ref Counter.
+ ///\sa Counter
+ class NoCounter
+ {
+ public:
+ typedef _NoSubCounter<NoCounter> SubCounter;
+ typedef _NoSubCounter<NoCounter> NoSubCounter;
+
+ NoCounter() {}
+ NoCounter(std::string,std::ostream &) {}
+ NoCounter(const char *,std::ostream &) {}
+ NoCounter(std::string) {}
+ NoCounter(const char *) {}
+ NoCounter &operator++() { return *this; }
+ int operator++(int) { return 0; }
+ NoCounter &operator--() { return *this; }
+ int operator--(int) { return 0; }
+ NoCounter &operator+=(int) { return *this;}
+ NoCounter &operator-=(int) { return *this;}
+ void reset(int) {}
+ void reset() {}
+ operator int() {return 0;}
+ };
+
+ ///@}
+}
+
+#endif
diff -r 407c08a0eae9 -r 35840c5aa696 lemon/time_measure.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lemon/time_measure.h Sat Apr 12 19:42:38 2008 +0100
@@ -0,0 +1,541 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2008
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_TIME_MEASURE_H
+#define LEMON_TIME_MEASURE_H
+
+///\ingroup timecount
+///\file
+///\brief Tools for measuring cpu usage
+
+#include <sys/times.h>
+
+#include <sys/time.h>
+#include <fstream>
+#include <iostream>
+#include <unistd.h>
+
+namespace lemon {
+
+ /// \addtogroup timecount
+ /// @{
+
+ /// A class to store (cpu)time instances.
+
+ /// This class stores five time values.
+ /// - a real time
+ /// - a user cpu time
+ /// - a system cpu time
+ /// - a user cpu time of children
+ /// - a system cpu time of children
+ ///
+ /// TimeStamp's can be added to or substracted from each other and
+ /// they can be pushed to a stream.
+ ///
+ /// In most cases, perhaps the \ref Timer or the \ref TimeReport
+ /// class is what you want to use instead.
+ ///
+ ///\author Alpar Juttner
+
+ class TimeStamp
+ {
+ struct rtms
+ {
+ double tms_utime;
+ double tms_stime;
+ double tms_cutime;
+ double tms_cstime;
+ rtms() {}
+ rtms(tms ts) : tms_utime(ts.tms_utime), tms_stime(ts.tms_stime),
+ tms_cutime(ts.tms_cutime), tms_cstime(ts.tms_cstime) {}
+ };
+ rtms ts;
+ double real_time;
+
+ rtms &getTms() {return ts;}
+ const rtms &getTms() const {return ts;}
+
+ void _reset() {
+ ts.tms_utime = ts.tms_stime = ts.tms_cutime = ts.tms_cstime = 0;
+ real_time = 0;
+ }
+
+ public:
+
+ ///Read the current time values of the process
+ void stamp()
+ {
+ timeval tv;
+ tms _ts;
+ times(&_ts);
+ gettimeofday(&tv, 0);real_time=tv.tv_sec+double(tv.tv_usec)/1e6;
+ ts=_ts;
+ }
+
+ /// Constructor initializing with zero
+ TimeStamp()
+ { _reset(); }
More information about the Lemon-commits
mailing list