-
-
Save JimBobSquarePants/3fc99b79520912b3c7febbbd52fe9e7a to your computer and use it in GitHub Desktop.
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; | |
} | |
} | |
} |
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
A quick Gist written as a response to http://stackoverflow.com/a/43324274/427899
NetCore 1.1 Console App referencing ImageSharp 1.0.0-alpha6-00066
This is really rough, there's no warmup time but it will give you a fair idea of general performance. Really it should use BenchMarkDotNet
Processor Details
Result - Time is in ms
Here's some better benchmarks using the code at https://github.com/bleroy/core-imaging-playground
https://gist.github.com/JimBobSquarePants/9fc411292724a9dbc3a887b9cfce157b