Prerequisites
Description
Drawing thinner lines takes much more time to process than broader lines.
The following tests were done on a 500x500 image (sorted by processing time):
- 100 lines with 10px: 448 ms
- 1000 lines with 10 px: 640 ms
- 100 lines with 1px: 1530 ms
- 1000 lines with 1px: 44680 ms
1000 10px lines render faster than 100 1px lines, which seems strange.
Steps to Reproduce
Option 1
Create a simple project, referencing the latest ImageSharp library and include the code below:
var numberOfLines = 100; // Update accordingly
var imageSize = 500; // Update accordingly
var lineWidth = 5; // Update accordingly
var lines = new List<int[]>();
var rnd = new Random(1);
for (int i = 0; i < numberOfLines; i++)
{
int pixelX = rnd.Next(imageSize);
int pixelY = rnd.Next(imageSize);
lines.Add(new int[] { pixelX, pixelY });
}
SixLabors.Primitives.PointF[] imageSharpLines = lines
.Select(r => new SixLabors.Primitives.PointF(r[0], r[1]))
.ToArray();
PointF[] systemDrawingLines = lines.Select(r => new PointF(r[0], r[1])).ToArray();
var w = new Stopwatch();
w.Start();
using (var image = new Image<Rgba32>(imageSize, imageSize))
{
image.Mutate(x => x
.DrawLines(
Rgba32.Red,
lineWidth,
imageSharpLines));
using (var stream = File.Create($"test-imageSharp-{imageSize}-{numberOfLines}-{lineWidth}.png"))
{
image.SaveAsPng(stream);
}
}
w.Stop();
Console.WriteLine($"Took {w.ElapsedMilliseconds} ms with ImageSharp");
Option 2
This was detected on a comparison between ImageSharp, System.Drawing and a custom simplified implementation. That benchmark is available at: https://github.com/pmcxs/core-linedrawing-benchmark/. It can be executed to replicate the issue:
- Clone the aforementioned repo
- Run it in Release. By default it will do various comparisons, including the ones specified above.
System Configuration
- ImageSharp version: 1.0.0-dev002737
- Environment (Operating system, version and so on): Windows 10 Pro
- .NET Framework version: .NET Core 2.1
Prerequisites
DEBUGandRELEASEmodeDescription
Drawing thinner lines takes much more time to process than broader lines.
The following tests were done on a 500x500 image (sorted by processing time):
1000 10px lines render faster than 100 1px lines, which seems strange.
Steps to Reproduce
Option 1
Create a simple project, referencing the latest ImageSharp library and include the code below:
Option 2
This was detected on a comparison between ImageSharp, System.Drawing and a custom simplified implementation. That benchmark is available at: https://github.com/pmcxs/core-linedrawing-benchmark/. It can be executed to replicate the issue:
System Configuration