FastLED 3.10.9
Loading...
Searching...
No Matches

◆ runPerlinBenchmark()

PerlinBenchResult autoresearch::animartrix_check::runPerlinBenchmark ( int iters)
inline

Definition at line 57 of file AutoResearchAnimartrixBench.h.

57 {
59 r.iterations = iters;
60
61 // Init the i16 implementation's fade lookup table once, off the
62 // benchmark clock. Function-local static so the linter's
63 // static-in-header rule stays happy and C++11's thread-safe init
64 // guarantees a single initialization across calls. The float path
65 // has no equivalent setup.
67 const int32_t* fade_lut = state.fade_lut;
68
69 constexpr int GRID = 16; // 16x16 pixel pass per iteration
70 constexpr float STEP_F = 0.05f; // Animartrix-typical pixel step in noise space
71 // Mirror in fixed-point: 0.05 in Q16.16 = 0.05 * 65536 ≈ 3277
72 constexpr int32_t STEP_I = static_cast<int32_t>(0.05f * 65536.0f);
73
74 // ── Float pnoise ──────────────────────────────────────────────
75 {
76 float ax = 0.0f, ay = 0.0f;
77 int32_t sink = 0;
78 uint32_t t0 = fl::micros();
79 for (int it = 0; it < iters; it++) {
80 // Slowly drift the origin across the iter so the compiler
81 // can't pre-compute. Same pattern Animartrix uses (the
82 // origin advances with `time_speed * dt` each frame).
83 ax += 0.011f;
84 ay += 0.013f;
85 for (int row = 0; row < GRID; row++) {
86 float y = ay + row * STEP_F;
87 for (int col = 0; col < GRID; col++) {
88 float x = ax + col * STEP_F;
89 float n = fl::pnoise(x, y, 0.0f);
90 // Map [-1, 1] → int8 the way Animartrix's output
91 // stage does. Sink to defeat DCE.
92 sink += static_cast<int32_t>(n * 127.0f);
93 }
94 }
95 }
96 uint32_t t1 = fl::micros();
97 state.sink = sink;
98 r.pnoise_float_us = static_cast<int64_t>(t1 - t0);
99 }
100
101 // ── i16 fixed-point pnoise2d ──────────────────────────────────
102 {
103 int32_t ax_i = 0, ay_i = 0;
104 // Q16.16 increment for the slow drift (matches 0.011, 0.013 in float)
105 constexpr int32_t DRIFT_X = static_cast<int32_t>(0.011f * 65536.0f);
106 constexpr int32_t DRIFT_Y = static_cast<int32_t>(0.013f * 65536.0f);
107 int32_t sink = 0;
108 uint32_t t0 = fl::micros();
109 for (int it = 0; it < iters; it++) {
110 ax_i += DRIFT_X;
111 ay_i += DRIFT_Y;
112 for (int row = 0; row < GRID; row++) {
113 int32_t y_i = ay_i + row * STEP_I;
114 for (int col = 0; col < GRID; col++) {
115 int32_t x_i = ax_i + col * STEP_I;
116 // pnoise2d_raw returns i32 Q16.16. Scale to int8
117 // the same way the float path does — divide by
118 // (HP_ONE / 127) so the magnitudes line up.
120 x_i, y_i, fade_lut, fl::PERLIN_NOISE);
121 sink += n >> 9; // crude scale; the actual op cost,
122 // not the value, is what we measure
123 }
124 }
125 }
126 uint32_t t1 = fl::micros();
127 state.sink = sink;
128 r.pnoise_i16_us = static_cast<int64_t>(t1 - t0);
129 }
130
131 return r;
132}
int y
Definition simple.h:93
int x
Definition simple.h:92
TestState state
fl::u32 uint32_t
Definition s16x16x4.h:219
FASTLED_FORCE_INLINE float pnoise(float x, float y, float z) FL_NO_EXCEPT
fl::u32 micros() FL_NO_EXCEPT
Universal microsecond timer - returns microseconds since system startup.
fl::i32 int32_t
Definition s16x16x4.h:220
static fl::i32 pnoise2d_raw(fl::i32 fx_raw, fl::i32 fy_raw, const fl::i32 *fade_lut, const fl::u8 *perm) FL_NO_EXCEPT

References autoresearch::animartrix_check::PerlinBenchResult::iterations, fl::micros(), perlinBenchState(), fl::pnoise(), fl::perlin_i16_optimized::pnoise2d_raw(), autoresearch::animartrix_check::PerlinBenchResult::pnoise_float_us, autoresearch::animartrix_check::PerlinBenchResult::pnoise_i16_us, state, x, and y.

+ Here is the call graph for this function: