Created
April 21, 2017 07:58
-
-
Save JimBobSquarePants/3fc99b79520912b3c7febbbd52fe9e7a to your computer and use it in GitHub Desktop.
Really Rough ImageSharp Benchmark.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.