// https://github.com/FastLED/FastLED/pull/1659
// benchmark of 100 calls to fill_gradient() for 2,400 LEDs
#include <FastLED.h>
#include "fill_gradient2.h"
#define kMatrixWidth 40
#define kMatrixHeight 60
#define NUM_LEDS ((kMatrixWidth) * (kMatrixHeight))
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812B, 3, GRB>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 4, GRB>(leds, NUM_LEDS);
Serial.begin(2000000);
Serial.println("Please wait ~3 seconds for benchmarking.");
}
void loop() {
const int iterations = 100;
uint8_t huestart = random() * 255;
uint8_t hueend = random() * 255;
uint32_t orig_us1 = micros();
for (uint32_t i = 0; i < iterations; i++)
fill_gradient(leds, NUM_LEDS, CHSV(huestart, 255, 255), CHSV(hueend, 255, 255), FORWARD_HUES);
uint32_t orig_us2 = micros();
FastLED[0].showLeds();
uint32_t fix_us1 = micros();
for (uint32_t i = 0; i < iterations; i++)
fill_gradient2(leds, NUM_LEDS, CHSV(huestart, 255, 255), CHSV(hueend, 255, 255), FORWARD_HUES);
uint32_t fix_us2 = micros();
FastLED[1].showLeds();
Serial.print(float(orig_us2 - orig_us1) / iterations);
Serial.print("μs vs ");
Serial.print(float(fix_us2 - fix_us1) / iterations);
Serial.print("μs % change: ");
Serial.println(float(fix_us2 - fix_us1) / float(orig_us2 - orig_us1) * 100.f - 100.f);
}