📷 A modern, cross-platform, 2D Graphics library for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

65 lines
1.8 KiB

// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Tests;
namespace SixLabors.ImageSharp.Benchmarks;
public class ParallelProcessing
{
private Image<Rgba32> image;
private Image<Rgba32> foreground;
private Configuration configuration;
public static IEnumerable<int> MaxDegreeOfParallelismValues()
{
int processorCount = Environment.ProcessorCount;
for (int p = 1; p <= processorCount; p *= 2)
{
yield return p;
}
if ((processorCount & (processorCount - 1)) != 0)
{
yield return processorCount;
}
}
[ParamsSource(nameof(MaxDegreeOfParallelismValues))]
public int MaxDegreeOfParallelism { get; set; }
[GlobalSetup]
public void Setup()
{
this.image = new Image<Rgba32>(2048, 2048);
this.foreground = new Image<Rgba32>(2048, 2048);
this.configuration = Configuration.Default.Clone();
this.configuration.MaxDegreeOfParallelism = this.MaxDegreeOfParallelism;
}
[Benchmark]
public void DetectEdges() => this.image.Mutate(this.configuration, x => x.DetectEdges());
[Benchmark]
public void DrawImage() => this.image.Mutate(this.configuration, x => x.DrawImage(this.foreground, 0.5f));
[Benchmark]
public void Crop()
{
Rectangle bounds = this.image.Bounds;
bounds = new Rectangle(1, 1, bounds.Width - 2, bounds.Height - 2);
this.image
.Clone(this.configuration, x => x.Crop(bounds))
.Dispose();
}
[GlobalCleanup]
public void Cleanup()
{
this.image.Dispose();
this.foreground.Dispose();
}
}