Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions src/benchmarks/micro/corefx/System.Drawing/Perf_Image_Load.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Extensions;
using MicroBenchmarks;

namespace System.Drawing.Tests
{
[BenchmarkCategory(Categories.CoreFX)]
public class Perf_Image_Load
{
private static readonly ImageTestData[] TestCases = {
new ImageTestData(ImageFormat.Bmp),
new ImageTestData(ImageFormat.Jpeg),
new ImageTestData(ImageFormat.Png),
new ImageTestData(ImageFormat.Gif)
};
// this field is lazy to avoid the exception during static ctor initialization of this type (harder to catch and handle properly)
private static readonly Lazy<ImageTestData[]> LazyTestCases = new Lazy<ImageTestData[]>(CreateTestCases);

public IEnumerable<object> ImageFormats() => TestCases;
public IEnumerable<object> ImageFormats() => LazyTestCases.Value;

[Benchmark]
[ArgumentsSource(nameof(ImageFormats))]
Expand Down Expand Up @@ -50,6 +46,28 @@ public void Image_FromStream_NoValidation(ImageTestData format)
}
}

private static ImageTestData[] CreateTestCases()
{
try
{
return new []
{
new ImageTestData(ImageFormat.Bmp),
new ImageTestData(ImageFormat.Jpeg),
new ImageTestData(ImageFormat.Png),
new ImageTestData(ImageFormat.Gif)
};
}
catch (Exception) when (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("libgdiplus is missing, you can install it by running 'apt-get install libgdiplus'");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it worth it to call out sudo here?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think so, the user might be already sudo or have permissions.

Console.ResetColor();

throw;
}
}

public class ImageTestData
{
public Stream Stream { get; }
Expand Down