|
|
|
@ -1,6 +1,7 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Diagnostics; |
|
|
|
|
|
|
|
using System.IO; |
|
|
|
using System.Linq; |
|
|
|
using System.Numerics; |
|
|
|
@ -23,24 +24,29 @@ namespace JpegBenchmark |
|
|
|
public static void Main(string[] args) |
|
|
|
{ |
|
|
|
var allData = ReadAllFiles(); |
|
|
|
|
|
|
|
bool methodSystemDrawing = args.Length > 0 && args[0].ToLower().Contains("system"); |
|
|
|
|
|
|
|
int times; |
|
|
|
if (args.Length == 0 || !int.TryParse(args[0], out times)) |
|
|
|
if (args.Length < 2 || !int.TryParse(args[1], out times)) |
|
|
|
{ |
|
|
|
times = 20; |
|
|
|
} |
|
|
|
|
|
|
|
Console.WriteLine($"Vector.IsHardwareAccelerated == {Vector.IsHardwareAccelerated}"); |
|
|
|
Console.WriteLine($"Method: {(methodSystemDrawing?"System.Drawing":"ImageSharp")}"); |
|
|
|
|
|
|
|
Console.WriteLine($"Decoding {allData.Length} jpegs X {times} times ..."); |
|
|
|
|
|
|
|
double estimatedTotalBlockCount = 0; |
|
|
|
|
|
|
|
Stopwatch sw = Stopwatch.StartNew(); |
|
|
|
for (int i = 0; i < times; i++) |
|
|
|
{ |
|
|
|
estimatedTotalBlockCount = DecodeAll(allData); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Func<byte[], double> method = methodSystemDrawing ? (Func<byte[], double>) DecodeMonoSystemDrawing : DecodeImageSharp; |
|
|
|
|
|
|
|
estimatedTotalBlockCount = DecodeAll(allData, times, method); |
|
|
|
|
|
|
|
|
|
|
|
sw.Stop(); |
|
|
|
|
|
|
|
Console.WriteLine($"Completed in {sw.ElapsedMilliseconds} ms"); |
|
|
|
@ -49,16 +55,36 @@ namespace JpegBenchmark |
|
|
|
Console.ReadLine(); |
|
|
|
} |
|
|
|
|
|
|
|
private static double DecodeAll(byte[][] allData) |
|
|
|
private static double DecodeImageSharp(byte[] data) |
|
|
|
{ |
|
|
|
var stream = new MemoryStream(data); |
|
|
|
Image img = new Image(stream); |
|
|
|
return img.Width * img.Height / 64.0; |
|
|
|
} |
|
|
|
|
|
|
|
private static double DecodeMonoSystemDrawing(byte[] data) |
|
|
|
{ |
|
|
|
var stream = new MemoryStream(data); |
|
|
|
var img = new System.Drawing.Bitmap(stream); |
|
|
|
return img.Width * img.Height / 64.0; |
|
|
|
} |
|
|
|
|
|
|
|
private static double DecodeAll(byte[][] allData, int times, Func<byte[], double> decoderFunc) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
double estimatedTotalBlockCount = 0; |
|
|
|
foreach (byte[] data in allData) |
|
|
|
|
|
|
|
for (int i = 0; i < times; i++) |
|
|
|
{ |
|
|
|
var stream = new MemoryStream(data); |
|
|
|
Image img = new Image(stream); |
|
|
|
estimatedTotalBlockCount = 0; |
|
|
|
foreach (byte[] data in allData) |
|
|
|
{ |
|
|
|
estimatedTotalBlockCount += decoderFunc(data); |
|
|
|
} |
|
|
|
|
|
|
|
estimatedTotalBlockCount += img.Width*img.Height/64.0; |
|
|
|
} |
|
|
|
|
|
|
|
return estimatedTotalBlockCount; |
|
|
|
} |
|
|
|
} |
|
|
|
|