]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/util/statistic/result_recorder.hpp
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / util / statistic / result_recorder.hpp
CommitLineData
36fed23c 1// -*- C++ -*-
2
fbd26352 3// Copyright (C) 2005-2019 Free Software Foundation, Inc.
36fed23c 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
6bc9506f 8// Foundation; either version 3, or (at your option) any later
36fed23c 9// version.
10
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.
15
16// You should have received a copy of the GNU General Public License
6bc9506f 17// along with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
19
36fed23c 20
21// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
22
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.
31
32/**
8b88dda3 33 * @file result_recorder.hpp
36fed23c 34 * Contains a class for recording results
35 */
36
37#ifndef PB_DS_RES_RECORDER_HPP
38#define PB_DS_RES_RECORDER_HPP
39
40#include <statistic/sample_mean.hpp>
8b88dda3 41#include <statistic/sample_variance.hpp>
36fed23c 42#include <statistic/sample_mean_confidence_checker.hpp>
43
b34535d7 44namespace __gnu_pbds
36fed23c 45{
36fed23c 46 namespace test
47 {
36fed23c 48 namespace detail
49 {
36fed23c 50 /*
51 * Records results until the probability that the sample mean is 10% away
8b88dda3 52 * from the true mean is ~ 0.05.
36fed23c 53 */
8b88dda3 54 template<typename Value_Type>
55 class result_recorder
36fed23c 56 {
57 public:
58 typedef Value_Type value_type;
59
8b88dda3 60 result_recorder()
61 : m_sample_mean(value_type()), m_sample_var(value_type())
62 { }
36fed23c 63
64 bool
8b88dda3 65 add_result(value_type res);
36fed23c 66
67 inline value_type
8b88dda3 68 get_sample_mean() const
69 { return m_sample_mean; }
36fed23c 70
71 private:
8b88dda3 72 typedef std::list<value_type> list_type;
36fed23c 73
8b88dda3 74 list_type m_l;
36fed23c 75 value_type m_sample_mean;
36fed23c 76 value_type m_sample_var;
77 };
78
36fed23c 79
8b88dda3 80 template<typename Value_Type>
36fed23c 81 bool
8b88dda3 82 result_recorder<Value_Type>::
83 add_result(value_type res)
36fed23c 84 {
85 m_l.push_back(res);
8b88dda3 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);
36fed23c 88
8b88dda3 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);
36fed23c 92 }
36fed23c 93 } // namespace detail
36fed23c 94 } // namespace test
b34535d7 95} // namespace __gnu_pbds
36fed23c 96
33b7ef52 97#endif
36fed23c 98