MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetAverageDurationMilliseconds

Method GetAverageDurationMilliseconds

src/framerate_gui.cpp:129–150  ·  view source on GitHub ↗

Get average cycle processing time over a number of data points */

Source from the content-addressed store, hash-verified

127
128 /** Get average cycle processing time over a number of data points */
129 double GetAverageDurationMilliseconds(int count)
130 {
131 count = std::min(count, this->num_valid);
132
133 int first_point = this->prev_index - count;
134 if (first_point < 0) first_point += NUM_FRAMERATE_POINTS;
135
136 /* Sum durations, skipping invalid points */
137 double sumtime = 0;
138 for (int i = first_point; i < first_point + count; i++) {
139 auto d = this->durations[i % NUM_FRAMERATE_POINTS];
140 if (d != INVALID_DURATION) {
141 sumtime += d;
142 } else {
143 /* Don't count the invalid durations */
144 count--;
145 }
146 }
147
148 if (count == 0) return 0; // avoid div by zero
149 return sumtime * 1000 / count / TIMESTAMP_PRECISION;
150 }
151
152 /** Get current rate of a performance element, based on approximately the past one second of data */
153 double GetRate()

Callers 2

UpdateDataMethod · 0.80
ConPrintFramerateFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected