Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
timer.hpp
Go to the documentation of this file.
1 /* -*- mode: c++; coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; show-trailing-whitespace: t -*-
2 
3  This file is part of the Feel library
4 
5  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
6  Date: 2012-03-20
7 
8  Copyright (C) 2012 Université Joseph Fourier (Grenoble I)
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 2.1 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
29 #if !defined( FEELPP_TIMING_TIMER_HPP)
30 #define FEELPP_TIMING_TIMER_HPP 1
31 
32 
33 #include <stack>
34 #include <boost/assert.hpp>
35 
36 namespace Feel
37 {
38 namespace details
39 {
41 // counter<R,T> is an implementation detail that gather and store cycles or
42 // seconds measures between tic and toc calls.
44 template<class R,class T> class counter
45 {
46 public :
47  typedef T timer_type;
48  typedef R type;
49 
50  void tic() const
51  {
52  times().push( time() );
53  }
54 
55  type toc( std::string const& msg, bool display ) const
56  {
57  BOOST_ASSERT_MSG( !empty(), "Unbalanced timing calls" );
58  type t = time()-times().top();
59  times().pop();
60 
61  if ( display ) timer_type::print( msg, t );
62 
63  return t;
64  }
65 
66  bool empty() const
67  {
68  return times().empty();
69  }
70  type time() const
71  {
72  return timer_type::time();
73  }
74 
75  std::stack<type>& times() const
76  {
77  static std::stack<type> local;
78  return local;
79  }
80 };
81 }
82 }
83 
84 #endif /* FEELPP_TIMING_TIMER_HPP */

Generated on Sun Dec 22 2013 13:11:15 for Feel++ by doxygen 1.8.5