3 // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 2, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
33 // Permission to use, copy, modify, sell, and distribute this software
34 // is hereby granted without fee, provided that the above copyright
35 // notice appears in all copies, and that both that copyright notice
36 // and this permission notice appear in supporting documentation. None
37 // of the above authors, nor IBM Haifa Research Laboratories, make any
38 // representation about the suitability of this software for any
39 // purpose. It is provided "as is" without express or implied
43 * @file timing_test_base.hpp
44 * Contains a base class for timing tests.
47 #ifndef PB_DS_TIMING_TEST_BASE_HPP
48 #define PB_DS_TIMING_TEST_BASE_HPP
50 #include <performance/time/elapsed_timer.hpp>
51 #include <statistic/result_recorder.hpp>
59 class timing_test_base
62 template<typename Functor
>
64 operator()(Functor
& fn
);
70 template<typename Functor
>
72 get_min_resolution(Functor
&);
74 template<typename Functor
>
76 run_at_resolution(Functor
&, std::size_t);
79 template<typename Functor
>
81 timing_test_base::operator()(Functor
& fn
)
83 const std::size_t resolution
= get_min_resolution(fn
);
84 __gnu_pbds::test::detail::result_recorder
<double> rec
;
87 res
= run_at_resolution(fn
, resolution
);
88 while (rec
.add_result(res
) == false);
89 res
= rec
.get_sample_mean() / resolution
;
94 timing_test_base::min_time_res()
97 template<typename Functor
>
99 timing_test_base::get_min_resolution(Functor
& fn
)
101 std::size_t guess
= 0;
102 const double epsilon_val
= min_time_res();
106 guess
= guess
* 2 + 1;
107 res
= run_at_resolution(fn
, guess
);
109 while (res
< epsilon_val
);
113 template<typename Functor
>
115 timing_test_base::run_at_resolution(Functor
& fn
, std::size_t resolution
)
122 } // namespace detail
124 } // namespace __gnu_pbds