1 /**
2  *   SFCGAL
3  *
4  *   Copyright (C) 2012-2013 Oslandia <infos@oslandia.com>
5  *   Copyright (C) 2012-2013 IGN (http://www.ign.fr)
6  *
7  *   This library is free software; you can redistribute it and/or
8  *   modify it under the terms of the GNU Library General Public
9  *   License as published by the Free Software Foundation; either
10  *   version 2 of the License, or (at your option) any later version.
11  *
12  *   This library is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *   Library General Public License for more details.
16 
17  *   You should have received a copy of the GNU Library General Public
18  *   License along with this library; if not, see <http://www.gnu.org/licenses/>.
19  */
20 #ifndef _SFCGAL_BENCH_H_
21 #define _SFCGAL_BENCH_H_
22 
23 #include <iostream>
24 #include <stack>
25 
26 #include <boost/timer/timer.hpp>
27 
28 #include <boost/format.hpp>
29 
30 namespace SFCGAL {
31 
32 /**
33  * @brief helper class to write formated benchs
34  */
35 class Bench {
36 public:
37     typedef boost::timer::cpu_timer timer_t ;
38 
39     /**
40      * destructor
41      */
42     ~Bench();
43 
44     /**
45      * start a bench
46      */
47     void start( const std::string& description ) ;
48     /**
49      * start a bench
50      */
51     void start( const boost::basic_format<char>& description ) ;
52     /**
53      * stop a bench
54      */
55     void stop() ;
56 
57     /**
58      * get bench instance
59      */
60     static Bench& instance() ;
61 
62     /**
63      * Get output stream
64      */
65     std::ostream& s() ;
66 private:
67     /**
68      * default constructor
69      */
70     Bench();
71     /**
72      * copy constructor
73      */
74     Bench( const Bench& bench );
75 
76     /**
77      * output stream to write bench result (default is std::cout)
78      */
79     std::ostream* _s ;
80     /**
81      * timer stack with description
82      */
83     std::stack< std::pair< std::string, timer_t > > _timers ;
84 };
85 
86 /**
87  * @Get bench instance
88  */
bench()89 inline Bench& bench()
90 {
91     return Bench::instance() ;
92 }
93 
94 } // namespace SFCGAL
95 
96 #endif
97 
98