FastLED 3.10.8
Loading...
Searching...
No Matches

◆ runPerlinBenchmark()

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

Definition at line 56 of file AutoResearchAnimartrixBench.h.

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