AD Teaching Wiki
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

FrontPage

AD Teaching Wiki:
  • attachment:Timer.h of SearchEnginesWS0910

Attachment 'Timer.h'

Download

   1 #ifndef __TIMER_H__
   2 #define __TIMER_H__
   3 
   4 #include <sys/time.h>
   5 
   6 //! A SIMPLE CLASS FOR TIME MEASUREMENTS.
   7 //
   8 class Timer
   9 {
  10   private:
  11 
  12     //! The timer value (initially zero)
  13     off_t _usecs;
  14 
  15     //! The timer value at the last mark set (initially zero)
  16     off_t _usecs_at_mark;
  17 
  18     //! Used by the gettimeofday command.
  19     struct timeval _tstart;
  20     
  21     //! Used by the gettimeofday command.
  22     struct timeval _tend;
  23     
  24     //! Used by the gettimeofday command.
  25     struct timezone _tz;
  26 
  27     //! Indicates whether a measurement is running.
  28     bool _running;
  29 
  30   public:
  31 
  32     //! The default constructor.
  33     Timer() { reset(); }
  34     
  35     //! Resets the timer value to zero and stops the measurement.
  36     void reset() { _usecs = _usecs_at_mark = 0; _running = false; }
  37 
  38     //! Mark the current point in time (to be considered by next usecs_since_mark)
  39     void mark() { stop(); _usecs_at_mark = _usecs; cont(); }
  40 
  41     //! Resets the timer value to zero and starts the measurement.
  42     inline void start()
  43     {
  44       _usecs = _usecs_at_mark = 0;
  45       gettimeofday(&_tstart, &_tz);
  46       _running = true;
  47     }
  48 
  49     //! Continues the measurement without resetting the timer value (no effect if running)
  50     inline void cont()
  51     { 
  52       if (_running == false)
  53       {
  54         gettimeofday(&_tstart, &_tz);
  55         _running = true;
  56       }
  57     }
  58     
  59     //! Stops the measurement (does *not* return the timer value anymore)
  60     inline void stop()
  61     {
  62       gettimeofday(&_tend, &_tz);
  63       if(_running){_usecs += (off_t)(1000000) * (off_t)(_tend.tv_sec - _tstart.tv_sec) + (off_t)(_tend.tv_usec - _tstart.tv_usec);}
  64       _running = false;
  65         //return _usecs;
  66     }
  67 
  68     //! Time at last stop (initially zero)
  69     off_t value() const { return _usecs; } /* in microseconds */
  70     off_t usecs() const { return _usecs; } /* in microseconds */
  71     off_t msecs() const { return _usecs/1000; } /* in milliseconds */
  72     float secs() const { return _usecs/1000000.0; } /* in seconds */
  73 
  74     //! Time from last mark to last stop (initally zero)
  75     off_t usecs_since_mark() const { return _usecs - _usecs_at_mark; }
  76 };
  77 
  78 #endif
  79 

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2010-02-04 18:41:13, 2.3 KB) [[attachment:HierarchicalClustering.cpp]]
  • [get | view] (2010-01-12 20:07:24, 2.2 KB) [[attachment:Timer.h]]
  • [get | view] (2010-01-24 15:42:29, 443.7 KB) [[attachment:dblp.txt]]
  • [get | view] (2009-10-22 14:29:03, 44.4 KB) [[attachment:exercise-1.pdf]]
  • [get | view] (2010-01-14 16:06:21, 69.4 KB) [[attachment:exercise-10.pdf]]
  • [get | view] (2010-01-21 14:53:18, 62.0 KB) [[attachment:exercise-11.pdf]]
  • [get | view] (2010-01-28 14:22:59, 61.3 KB) [[attachment:exercise-12.pdf]]
  • [get | view] (2010-02-04 15:31:54, 59.0 KB) [[attachment:exercise-13.pdf]]
  • [get | view] (2010-02-15 17:47:13, 50.9 KB) [[attachment:exercise-14.pdf]]
  • [get | view] (2009-10-29 15:03:08, 43.5 KB) [[attachment:exercise-2.pdf]]
  • [get | view] (2009-11-05 15:24:10, 45.8 KB) [[attachment:exercise-3.pdf]]
  • [get | view] (2009-11-12 15:40:55, 55.2 KB) [[attachment:exercise-4.pdf]]
  • [get | view] (2009-11-20 03:16:57, 53.1 KB) [[attachment:exercise-5.pdf]]
  • [get | view] (2010-03-10 16:24:50, 68.6 KB) [[attachment:exercise-6.pdf]]
  • [get | view] (2009-12-03 15:42:36, 43.2 KB) [[attachment:exercise-7.pdf]]
  • [get | view] (2009-12-22 19:37:35, 57.5 KB) [[attachment:exercise-8.pdf]]
  • [get | view] (2010-01-13 23:57:57, 55.4 KB) [[attachment:exercise-9.pdf]]
  • [get | view] (2009-10-23 16:02:29, 93.8 KB) [[attachment:lecture-1.pdf]]
  • [get | view] (2010-01-17 13:46:23, 162.4 KB) [[attachment:lecture-10.pdf]]
  • [get | view] (2010-01-21 22:21:41, 154.9 KB) [[attachment:lecture-11.pdf]]
  • [get | view] (2010-01-29 16:11:40, 231.0 KB) [[attachment:lecture-12.pdf]]
  • [get | view] (2010-02-04 18:34:40, 147.8 KB) [[attachment:lecture-13.pdf]]
  • [get | view] (2010-02-11 19:36:02, 233.2 KB) [[attachment:lecture-14.pdf]]
  • [get | view] (2009-10-30 00:06:50, 198.7 KB) [[attachment:lecture-2.pdf]]
  • [get | view] (2009-11-05 21:15:21, 106.4 KB) [[attachment:lecture-3.pdf]]
  • [get | view] (2009-11-12 15:53:25, 193.3 KB) [[attachment:lecture-4.pdf]]
  • [get | view] (2009-11-19 03:29:30, 168.2 KB) [[attachment:lecture-5.pdf]]
  • [get | view] (2009-11-27 02:32:33, 151.1 KB) [[attachment:lecture-6.pdf]]
  • [get | view] (2009-12-03 21:22:18, 68.0 KB) [[attachment:lecture-7.pdf]]
  • [get | view] (2009-12-10 21:46:26, 156.3 KB) [[attachment:lecture-8.pdf]]
  • [get | view] (2010-01-07 18:55:37, 127.0 KB) [[attachment:lecture-9.pdf]]
  • [get | view] (2010-02-11 19:42:15, 110.5 KB) [[attachment:lecture-projects.pdf]]
  • [get | view] (2009-12-03 21:20:02, 10.0 KB) [[attachment:prefix-search.tar]]
  • [get | view] (2010-03-10 16:18:17, 68.2 KB) [[attachment:solution-10.pdf]]
  • [get | view] (2010-03-06 18:57:52, 53.0 KB) [[attachment:solution-11.pdf]]
  • [get | view] (2010-03-08 13:55:50, 6.3 KB) [[attachment:solution-12-1.cpp]]
  • [get | view] (2010-03-08 14:16:18, 109.0 KB) [[attachment:solution-12.pdf]]
  • [get | view] (2010-03-10 16:38:55, 44.8 KB) [[attachment:solution-6.pdf]]
  • [get | view] (2010-01-19 13:59:48, 80.4 KB) [[attachment:solution-9.pdf]]
  • [get | view] (2010-03-07 12:59:19, 85.9 KB) [[attachment:solution-midterm.pdf]]
  • [get | view] (2009-11-08 15:22:20, 25.1 KB) [[attachment:trec_queries.txt]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.

  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01