-
Notifications
You must be signed in to change notification settings - Fork 981
Description
This isn't a bug per se, more of a significant change in performance. Although the example program is unrealistic, the performance difference is significant enough it still may cause performance issues when using a small number of colors.
That being said, it's unlikely the average user would encounter this, so it may not be worth addressing, I just thought I'd mention it.
It appears this was introduced in commit 3da89c3 as a fix to issue #4175
Issue: Accessing colors in a colormap is approximately 500 times slower than in the previous version
ScottPlot Version: ScottPlot.WPF 5.0.38
using System.Diagnostics;
using ScottPlot;
var colorMap = new ScottPlot.Colormaps.Algae();
var plot = new ScottPlot.Plot();
var startTime = Stopwatch.GetTimestamp();
var iterations = 0;
for(int count = 1; count < 256; count++)
{
var xs = Generate.Consecutive(count);
var ys = Generate.Repeating(count, count);
var colors = colorMap.GetColors(count);
for(int i=0; i<count; i++)
{
var circle = plot.Add.Circle(xs[i], ys[i], 0.45);
circle.FillColor = colors[i];
circle.LineWidth = 0;
iterations++;
}
}
var totalSeconds = Stopwatch.GetElapsedTime(startTime).TotalSeconds;
Console.WriteLine($"{iterations:N0} iterations in {totalSeconds:N2} seconds. {iterations/totalSeconds:N2} iterations/sec");
plot.SavePng("colorMapTest.png", 1080, 1080);To reproduce, run the above with version 5.0.38, then with 5.0.37.
Results:
5.0.37 - 32,640 iterations in 0.01 seconds. 3,449,952.44 iterations/sec
5.0.38 - 32,640 iterations in 5.16 seconds. 6,330.13 iterations/sec