Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Timer.hpp

Go to the documentation of this file.
00001 /*==========================================================================
00002  * Copyright (c) 2001 Carnegie Mellon University.  All Rights Reserved.
00003  *
00004  * Use of the Lemur Toolkit for Language Modeling and Information Retrieval
00005  * is subject to the terms of the software license set forth in the LICENSE
00006  * file included with this software, and also available at
00007  * http://www.cs.cmu.edu/~lemur/license.html
00008  *
00009  *==========================================================================
00010 */
00011 
00012 
00013 #ifndef _TIMERH_
00014 #define _TIMERH_
00015 
00016 #include <ctime>
00017 #include "common_headers.hpp"
00018 #include "String.hpp"
00019 
00020 class Timer {
00021 public:
00022   Timer(const String &string, int start=1) : message(string)
00023     { if (start) Start(); }
00024   void Start()
00025     {
00026       time(&t);
00027       cerr << "Beginning: " << message << endl << flush;
00028     }
00029   ~Timer() { if (t > 0) Stop(); }
00030   void Stop()
00031     {
00032       time_t total;
00033       time(&total);
00034       total -= t;
00035       cerr << message << " total time: ";
00036       if (total/3600) { cerr << total/3600 << " hours ";   total %= 3600; }
00037       if (total/60)   { cerr << total/60   << " minutes "; total %= 60; }
00038       cerr << total      << " seconds " << endl << flush;
00039       t = 0;
00040     }
00041   void Elapsed()
00042     {
00043       time_t total;
00044       time(&total);
00045       total -= t;
00046       cerr << message << " elapsed time: ";
00047       if (total/3600) { cerr << total/3600 << " hours ";   total %= 3600; }
00048       if (total/60)   { cerr << total/60   << " minutes "; total %= 60; }
00049       cerr << total      << " seconds " << endl << flush;
00050     }
00051   time_t getElapsed() const { time_t cur; time(&cur); return cur - t; }
00052 private:
00053   time_t t;
00054   String message;
00055 };
00056 
00057     
00058 
00059 #endif

Generated at Fri Jul 26 18:22:27 2002 for LEMUR by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000