Blender  V2.93
deg_time_average.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2013 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #pragma once
25 
26 namespace blender {
27 namespace deg {
28 
29 // Utility class which takes care of calculating average of time series, such as
30 // FPS counters.
31 template<int MaxSamples> class AveragedTimeSampler {
32  public:
34  {
35  }
36 
37  void add_sample(double value)
38  {
40 
41  // Move to the next index, keeping wrapping at the end of array into account.
43  if (next_sample_index_ == MaxSamples) {
45  }
46 
47  // Update number of stored samples.
48  if (num_samples_ != MaxSamples) {
49  ++num_samples_;
50  }
51  }
52 
53  double get_averaged() const
54  {
55  double sum = 0.0;
56  for (int i = 0; i < num_samples_; ++i) {
57  sum += samples_[i];
58  }
59  return sum / num_samples_;
60  }
61 
62  protected:
63  double samples_[MaxSamples];
64 
65  // Number of samples which are actually stored in the array.
67 
68  // Index in the samples_ array under which next sample will be stored.
70 };
71 
72 } // namespace deg
73 } // namespace blender
static T sum(const btAlignedObjectArray< T > &items)