2018-03-08 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libstdc++-v3 / testsuite / util / statistic / result_recorder.hpp
blobb7f4b655ce3bc42bec6111aef73f7397d5a76bbe
1 // -*- C++ -*-
3 // Copyright (C) 2005-2018 Free Software Foundation, Inc.
4 //
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 3, or (at your option) any later
9 // version.
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 COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
21 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
23 // Permission to use, copy, modify, sell, and distribute this software
24 // is hereby granted without fee, provided that the above copyright
25 // notice appears in all copies, and that both that copyright notice
26 // and this permission notice appear in supporting documentation. None
27 // of the above authors, nor IBM Haifa Research Laboratories, make any
28 // representation about the suitability of this software for any
29 // purpose. It is provided "as is" without express or implied
30 // warranty.
32 /**
33 * @file result_recorder.hpp
34 * Contains a class for recording results
37 #ifndef PB_DS_RES_RECORDER_HPP
38 #define PB_DS_RES_RECORDER_HPP
40 #include <statistic/sample_mean.hpp>
41 #include <statistic/sample_variance.hpp>
42 #include <statistic/sample_mean_confidence_checker.hpp>
44 namespace __gnu_pbds
46 namespace test
48 namespace detail
51 * Records results until the probability that the sample mean is 10% away
52 * from the true mean is ~ 0.05.
54 template<typename Value_Type>
55 class result_recorder
57 public:
58 typedef Value_Type value_type;
60 result_recorder()
61 : m_sample_mean(value_type()), m_sample_var(value_type())
62 { }
64 bool
65 add_result(value_type res);
67 inline value_type
68 get_sample_mean() const
69 { return m_sample_mean; }
71 private:
72 typedef std::list<value_type> list_type;
74 list_type m_l;
75 value_type m_sample_mean;
76 value_type m_sample_var;
80 template<typename Value_Type>
81 bool
82 result_recorder<Value_Type>::
83 add_result(value_type res)
85 m_l.push_back(res);
86 m_sample_mean = sample_mean(m_l.begin(), m_l.end());
87 m_sample_var = sample_variance(m_l.begin(), m_l.end(), m_sample_mean);
89 size_t dist = std::distance(m_l.begin(), m_l.end());
90 return sample_mean_confidence_checker(m_sample_mean, m_sample_var,
91 dist, 0.1);
93 } // namespace detail
94 } // namespace test
95 } // namespace __gnu_pbds
97 #endif