Skip to content

Instantly share code, notes, and snippets.

@JimBobSquarePants
Created April 21, 2017 07:58
Show Gist options
  • Save JimBobSquarePants/3fc99b79520912b3c7febbbd52fe9e7a to your computer and use it in GitHub Desktop.
Save JimBobSquarePants/3fc99b79520912b3c7febbbd52fe9e7a to your computer and use it in GitHub Desktop.
Really Rough ImageSharp Benchmark.
using System;
using System.IO;
using System.Numerics;
using System.Reflection;
using ImageSharp;
using ImageSharp.Processing;
namespace Test.ISharp
{
class Program
{
static void Main(string[] args)
{
string input = Path.Combine(GetAssemblyPath(), "../../../input");
string output = Path.Combine(GetAssemblyPath(), "../../../output");
if (!Directory.Exists(output))
{
Directory.CreateDirectory(output);
}
Console.WriteLine($"{IntPtr.Size * 8}-Bit");
Console.WriteLine($"Hardware-Accelerated: {Vector.IsHardwareAccelerated}");
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
foreach (string file in Directory.GetFiles(input))
{
string name = Path.GetFileName(file);
using (FileStream inputStream = File.OpenRead(file))
using (FileStream outputStream = File.Create(Path.Combine(output, name)))
using (Image image = Image.Load(inputStream))
{
image.Resize(new ResizeOptions()
{
Mode = ResizeMode.Max,
Sampler = new Lanczos3Resampler(),
Size = new Size(300, 300)
}).SaveAsJpeg(outputStream); // Quality is already 75
}
}
sw.Stop();
Console.WriteLine($"Elapsed time: {sw.Elapsed.TotalMilliseconds}");
}
private static string GetAssemblyPath()
{
string assemblyLocation = typeof(Program).GetTypeInfo().Assembly.Location;
assemblyLocation = Path.GetDirectoryName(assemblyLocation);
if (assemblyLocation != null)
{
assemblyLocation = Path.GetFullPath(assemblyLocation);
}
return assemblyLocation;
}
}
}
@ststeiger
Copy link

ststeiger commented Apr 21, 2017

I quickly added a quick&dirty test-web-application here.
Checking for extension .JPG just for quick&dirty security reasons.

Below are my Windows-system specs, but the 13 seconds were on the Linux-server.
It's possible "dotnet build" created a debug-mode application on the server, though.
I had some trouble with the precompiled application with dotnet-dev-rc4, so I pulled from github and built from source on the command-line.
Currently runs on dotnet-dev-1.0.1 there.
By the way, would be nice if there were an ImageSharp package for .NET Core 1.1, I'd like to see what difference there is when running ImageSharp in debug mode from nuget vs. from source.

CPU-Architecture: AMD64
App-Architecture: 64-Bit
HW-Acc.: True
CPUinfo:
Intel(R) Core(TM) i5-2540M CPU @ 2.60GHz
Intel64 Family 6 Model 42 Stepping 7
Cores: 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment