libpnicore
clock_timer.hpp
1 //
2 // (c) Copyright 2012 DESY, Eugen Wintersberger <eugen.wintersberger@desy.de>
3 //
4 // This file is part of libpniio.
5 //
6 // libpniio is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // libpniio is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with libpniio. If not, see <http://www.gnu.org/licenses/>.
18 //
19 // ============================================================================
20 //
21 // Created on: Oct 24, 2012
22 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
23 //
24 #pragma once
25 #include "../types.hpp"
26 
27 #include<iostream>
28 #include<ctime>
29 
30 namespace pni{
31 namespace core{
32 
42  {
43  private:
44  clock_t _start;
45  clock_t _stop;
46 
47  public:
48  //======================static members=================================
50  static const string name;
51  //=======================constructors==================================
53  clock_timer():_start(0),_stop(0) {}
54 
55  //========================public member functions======================
62  void start() { _start = clock(); }
63 
64  //---------------------------------------------------------------------
71  void stop() { _stop = clock(); }
72 
73  //---------------------------------------------------------------------
82  float64 duration() const
83  {
84  return ((double)(_stop-_start))/CLOCKS_PER_SEC;
85  }
86 
87  //---------------------------------------------------------------------
89  string unit() const
90  {
91  return string("s");
92  }
93  };
94 
95 
96 //end of namespace
97 }
98 }
void start()
set start value
Definition: clock_timer.hpp:62
clock_t _start
start time
Definition: clock_timer.hpp:44
string unit() const
get time unit
Definition: clock_timer.hpp:89
Definition: add_op.hpp:29
float64 duration() const
get duration
Definition: clock_timer.hpp:82
static const string name
name of the timer
Definition: clock_timer.hpp:50
double float64
64Bit IEEE floating point type
Definition: types/types.hpp:56
void stop()
set stop value
Definition: clock_timer.hpp:71
clock_t _stop
stop time
Definition: clock_timer.hpp:45
clock() timer
Definition: clock_timer.hpp:41
std::string string
String type.
Definition: types/types.hpp:69
clock_timer()
default constructor
Definition: clock_timer.hpp:53