FastLED 3.10.6
Loading...
Searching...
No Matches

◆ runWavePerfRepeat()

WavePerfRepeatResult fl::wave_perf::runWavePerfRepeat ( u32 W,
u32 H,
u32 iterations,
u32 repeats,
LaplacianStencil stencil )
inline

Definition at line 146 of file wave_perf_bench.h.

148 {
150 if (!isValidGrid(W, H) || !isValidIterations(iterations)
151 || !isValidRepeats(repeats)) {
152 return r;
153 }
154 // Single sim reused across repeats — the warm-up cost is paid once
155 // and each repeat measures steady-state cost.
156 auto sim = makeBenchSim(W, H, stencil);
157 double sum = 0.0;
158 double sum_sq = 0.0;
159 for (u32 j = 0; j < repeats; ++j) {
160 const u32 t0 = fl::micros();
161 for (u32 i = 0; i < iterations; ++i) {
162 sim->update();
163 }
164 const u32 t1 = fl::micros();
165 const double us_per_update =
166 static_cast<double>(t1 - t0) / static_cast<double>(iterations);
167 sum += us_per_update;
168 sum_sq += us_per_update * us_per_update;
169 }
170 const double mean = sum / static_cast<double>(repeats);
171 const double variance = (sum_sq / static_cast<double>(repeats))
172 - (mean * mean);
173 double std_dev = 0.0;
174 if (variance > 0.0) {
175 // Newton-Raphson sqrt — avoids pulling in <cmath> on platforms
176 // where it's costly. 6 iterations gives ~14 significant digits.
177 double s = variance;
178 for (int k = 0; k < 6; ++k) {
179 s = 0.5 * (s + variance / s);
180 }
181 std_dev = s;
182 }
183 r.success = true;
184 r.repeats = repeats;
185 r.mean_us_per_update = mean;
186 r.std_dev_us_per_update = std_dev;
187 r.std_dev_pct = (mean > 0.0) ? (100.0 * std_dev / mean) : 0.0;
188 return r;
189}
static const int H
Definition PerfDisc.ino:21
static const int W
Definition PerfDisc.ino:20
bool isValidRepeats(u32 repeats) FL_NO_EXCEPT
fl::unique_ptr< WaveSimulation2D_Real > makeBenchSim(u32 W, u32 H, LaplacianStencil stencil) FL_NO_EXCEPT
bool isValidIterations(u32 iterations) FL_NO_EXCEPT
bool isValidGrid(u32 W, u32 H) FL_NO_EXCEPT
fl::u32 micros()
Universal microsecond timer - returns microseconds since system startup.

References fl::FL_NO_EXCEPT, H, isValidGrid(), isValidIterations(), isValidRepeats(), makeBenchSim(), fl::wave_perf::WavePerfRepeatResult::mean_us_per_update, fl::micros(), fl::wave_perf::WavePerfRepeatResult::repeats, fl::wave_perf::WavePerfRepeatResult::std_dev_pct, fl::wave_perf::WavePerfRepeatResult::std_dev_us_per_update, fl::wave_perf::WavePerfRepeatResult::success, and W.

+ Here is the call graph for this function: