mirror of https://github.com/SixLabors/ImageSharp
11 changed files with 415 additions and 274 deletions
@ -1,131 +0,0 @@ |
|||||
// <copyright file="Decode.cs" company="James Jackson-South">
|
|
||||
// Copyright (c) James Jackson-South and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
// </copyright>
|
|
||||
|
|
||||
namespace ImageSharp.Benchmarks.Image |
|
||||
{ |
|
||||
using System.Drawing; |
|
||||
using System.IO; |
|
||||
|
|
||||
using BenchmarkDotNet.Attributes; |
|
||||
using CoreSize = ImageSharp.Size; |
|
||||
using CoreImage = ImageSharp.Image; |
|
||||
|
|
||||
public class Decode |
|
||||
{ |
|
||||
private byte[] bmpBytes; |
|
||||
private byte[] gifBytes; |
|
||||
private byte[] jpegBytes; |
|
||||
private byte[] pngBytes; |
|
||||
|
|
||||
[Setup] |
|
||||
public void ReadImages() |
|
||||
{ |
|
||||
if (bmpBytes == null) |
|
||||
{ |
|
||||
bmpBytes = File.ReadAllBytes("../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp"); |
|
||||
} |
|
||||
if (gifBytes == null) |
|
||||
{ |
|
||||
gifBytes = File.ReadAllBytes("../ImageSharp.Tests/TestImages/Formats/Gif/rings.gif"); |
|
||||
} |
|
||||
if (jpegBytes == null) |
|
||||
{ |
|
||||
jpegBytes = File.ReadAllBytes("../ImageSharp.Tests/TestImages/Formats/Jpg/Calliphora.jpg"); |
|
||||
} |
|
||||
if (pngBytes == null) |
|
||||
{ |
|
||||
pngBytes = File.ReadAllBytes("../ImageSharp.Tests/TestImages/Formats/Png/splash.png"); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "System.Drawing Bmp")] |
|
||||
public Size BmpSystemDrawing() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream(bmpBytes)) |
|
||||
{ |
|
||||
using (Image image = Image.FromStream(memoryStream)) |
|
||||
{ |
|
||||
return image.Size; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "ImageSharp Bmp")] |
|
||||
public CoreSize BmpCore() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream(bmpBytes)) |
|
||||
{ |
|
||||
CoreImage image = new CoreImage(memoryStream); |
|
||||
return new CoreSize(image.Width, image.Height); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "System.Drawing Gif")] |
|
||||
public Size GifSystemDrawing() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream(gifBytes)) |
|
||||
{ |
|
||||
using (Image image = Image.FromStream(memoryStream)) |
|
||||
{ |
|
||||
return image.Size; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "ImageSharp Gif")] |
|
||||
public CoreSize GifCore() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream(gifBytes)) |
|
||||
{ |
|
||||
CoreImage image = new CoreImage(memoryStream); |
|
||||
return new CoreSize(image.Width, image.Height); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "System.Drawing Jpeg")] |
|
||||
public Size JpegSystemDrawing() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream(jpegBytes)) |
|
||||
{ |
|
||||
using (Image image = Image.FromStream(memoryStream)) |
|
||||
{ |
|
||||
return image.Size; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "ImageSharp Jpeg")] |
|
||||
public CoreSize JpegCore() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream(jpegBytes)) |
|
||||
{ |
|
||||
CoreImage image = new CoreImage(memoryStream); |
|
||||
return new CoreSize(image.Width, image.Height); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "System.Drawing Png")] |
|
||||
public Size PngSystemDrawing() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream(pngBytes)) |
|
||||
{ |
|
||||
using (Image image = Image.FromStream(memoryStream)) |
|
||||
{ |
|
||||
return image.Size; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "ImageSharp Png")] |
|
||||
public CoreSize PngCore() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream(pngBytes)) |
|
||||
{ |
|
||||
CoreImage image = new CoreImage(memoryStream); |
|
||||
return new CoreSize(image.Width, image.Height); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,51 @@ |
|||||
|
// <copyright file="DecodeBmp.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Benchmarks.Image |
||||
|
{ |
||||
|
using System.Drawing; |
||||
|
using System.IO; |
||||
|
|
||||
|
using BenchmarkDotNet.Attributes; |
||||
|
|
||||
|
using CoreImage = ImageSharp.Image; |
||||
|
using CoreSize = ImageSharp.Size; |
||||
|
|
||||
|
public class DecodeBmp |
||||
|
{ |
||||
|
private byte[] bmpBytes; |
||||
|
|
||||
|
[Setup] |
||||
|
public void ReadImages() |
||||
|
{ |
||||
|
if (this.bmpBytes == null) |
||||
|
{ |
||||
|
this.bmpBytes = File.ReadAllBytes("../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Baseline = true, Description = "System.Drawing Bmp")] |
||||
|
public Size BmpSystemDrawing() |
||||
|
{ |
||||
|
using (MemoryStream memoryStream = new MemoryStream(this.bmpBytes)) |
||||
|
{ |
||||
|
using (Image image = Image.FromStream(memoryStream)) |
||||
|
{ |
||||
|
return image.Size; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Description = "ImageSharp Bmp")] |
||||
|
public CoreSize BmpCore() |
||||
|
{ |
||||
|
using (MemoryStream memoryStream = new MemoryStream(this.bmpBytes)) |
||||
|
{ |
||||
|
CoreImage image = new CoreImage(memoryStream); |
||||
|
return new CoreSize(image.Width, image.Height); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,51 @@ |
|||||
|
// <copyright file="DecodeGif.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Benchmarks.Image |
||||
|
{ |
||||
|
using System.Drawing; |
||||
|
using System.IO; |
||||
|
|
||||
|
using BenchmarkDotNet.Attributes; |
||||
|
|
||||
|
using CoreImage = ImageSharp.Image; |
||||
|
using CoreSize = ImageSharp.Size; |
||||
|
|
||||
|
public class DecodeGif |
||||
|
{ |
||||
|
private byte[] gifBytes; |
||||
|
|
||||
|
[Setup] |
||||
|
public void ReadImages() |
||||
|
{ |
||||
|
if (this.gifBytes == null) |
||||
|
{ |
||||
|
this.gifBytes = File.ReadAllBytes("../ImageSharp.Tests/TestImages/Formats/Gif/rings.gif"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Baseline = true, Description = "System.Drawing Gif")] |
||||
|
public Size GifSystemDrawing() |
||||
|
{ |
||||
|
using (MemoryStream memoryStream = new MemoryStream(this.gifBytes)) |
||||
|
{ |
||||
|
using (Image image = Image.FromStream(memoryStream)) |
||||
|
{ |
||||
|
return image.Size; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Description = "ImageSharp Gif")] |
||||
|
public CoreSize GifCore() |
||||
|
{ |
||||
|
using (MemoryStream memoryStream = new MemoryStream(this.gifBytes)) |
||||
|
{ |
||||
|
CoreImage image = new CoreImage(memoryStream); |
||||
|
return new CoreSize(image.Width, image.Height); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,51 @@ |
|||||
|
// <copyright file="DecodeJpeg.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Benchmarks.Image |
||||
|
{ |
||||
|
using System.Drawing; |
||||
|
using System.IO; |
||||
|
|
||||
|
using BenchmarkDotNet.Attributes; |
||||
|
|
||||
|
using CoreImage = ImageSharp.Image; |
||||
|
using CoreSize = ImageSharp.Size; |
||||
|
|
||||
|
public class DecodeJpeg |
||||
|
{ |
||||
|
private byte[] jpegBytes; |
||||
|
|
||||
|
[Setup] |
||||
|
public void ReadImages() |
||||
|
{ |
||||
|
if (this.jpegBytes == null) |
||||
|
{ |
||||
|
this.jpegBytes = File.ReadAllBytes("../ImageSharp.Tests/TestImages/Formats/Jpg/Calliphora.jpg"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Baseline = true, Description = "System.Drawing Jpeg")] |
||||
|
public Size JpegSystemDrawing() |
||||
|
{ |
||||
|
using (MemoryStream memoryStream = new MemoryStream(this.jpegBytes)) |
||||
|
{ |
||||
|
using (Image image = Image.FromStream(memoryStream)) |
||||
|
{ |
||||
|
return image.Size; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Description = "ImageSharp Jpeg")] |
||||
|
public CoreSize JpegCore() |
||||
|
{ |
||||
|
using (MemoryStream memoryStream = new MemoryStream(this.jpegBytes)) |
||||
|
{ |
||||
|
CoreImage image = new CoreImage(memoryStream); |
||||
|
return new CoreSize(image.Width, image.Height); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,51 @@ |
|||||
|
// <copyright file="DecodePng.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Benchmarks.Image |
||||
|
{ |
||||
|
using System.Drawing; |
||||
|
using System.IO; |
||||
|
|
||||
|
using BenchmarkDotNet.Attributes; |
||||
|
|
||||
|
using CoreImage = ImageSharp.Image; |
||||
|
using CoreSize = ImageSharp.Size; |
||||
|
|
||||
|
public class DecodePng |
||||
|
{ |
||||
|
private byte[] pngBytes; |
||||
|
|
||||
|
[Setup] |
||||
|
public void ReadImages() |
||||
|
{ |
||||
|
if (this.pngBytes == null) |
||||
|
{ |
||||
|
this.pngBytes = File.ReadAllBytes("../ImageSharp.Tests/TestImages/Formats/Png/splash.png"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Baseline = true, Description = "System.Drawing Png")] |
||||
|
public Size PngSystemDrawing() |
||||
|
{ |
||||
|
using (MemoryStream memoryStream = new MemoryStream(this.pngBytes)) |
||||
|
{ |
||||
|
using (Image image = Image.FromStream(memoryStream)) |
||||
|
{ |
||||
|
return image.Size; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Description = "ImageSharp Png")] |
||||
|
public CoreSize PngCore() |
||||
|
{ |
||||
|
using (MemoryStream memoryStream = new MemoryStream(this.pngBytes)) |
||||
|
{ |
||||
|
CoreImage image = new CoreImage(memoryStream); |
||||
|
return new CoreSize(image.Width, image.Height); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,141 +0,0 @@ |
|||||
// <copyright file="Encode.cs" company="James Jackson-South">
|
|
||||
// Copyright (c) James Jackson-South and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
// </copyright>
|
|
||||
|
|
||||
namespace ImageSharp.Benchmarks.Image |
|
||||
{ |
|
||||
using System.Drawing; |
|
||||
using System.Drawing.Imaging; |
|
||||
using System.IO; |
|
||||
|
|
||||
using BenchmarkDotNet.Attributes; |
|
||||
using CoreImage = ImageSharp.Image; |
|
||||
|
|
||||
public class Encode |
|
||||
{ |
|
||||
// System.Drawing needs this.
|
|
||||
private Stream bmpStream; |
|
||||
private Stream gifStream; |
|
||||
private Stream jpegStream; |
|
||||
private Stream pngStream; |
|
||||
|
|
||||
private Image bmpDrawing; |
|
||||
private Image gifDrawing; |
|
||||
private Image jpegDrawing; |
|
||||
private Image pngDrawing; |
|
||||
|
|
||||
private CoreImage bmpCore; |
|
||||
private CoreImage gifCore; |
|
||||
private CoreImage jpegCore; |
|
||||
private CoreImage pngCore; |
|
||||
|
|
||||
[Setup] |
|
||||
public void ReadImages() |
|
||||
{ |
|
||||
if (bmpStream == null) |
|
||||
{ |
|
||||
bmpStream = File.OpenRead("../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp"); |
|
||||
bmpCore = new CoreImage(bmpStream); |
|
||||
bmpStream.Position = 0; |
|
||||
bmpDrawing = Image.FromStream(bmpStream); |
|
||||
} |
|
||||
|
|
||||
if (gifStream == null) |
|
||||
{ |
|
||||
gifStream = File.OpenRead("../ImageSharp.Tests/TestImages/Formats/Gif/rings.gif"); |
|
||||
gifCore = new CoreImage(gifStream); |
|
||||
gifStream.Position = 0; |
|
||||
gifDrawing = Image.FromStream(gifStream); |
|
||||
} |
|
||||
|
|
||||
if (jpegStream == null) |
|
||||
{ |
|
||||
jpegStream = File.OpenRead("../ImageSharp.Tests/TestImages/Formats/Jpg/Calliphora.jpg"); |
|
||||
jpegCore = new CoreImage(jpegStream); |
|
||||
jpegStream.Position = 0; |
|
||||
jpegDrawing = Image.FromStream(jpegStream); |
|
||||
} |
|
||||
|
|
||||
if (pngStream == null) |
|
||||
{ |
|
||||
pngStream = File.OpenRead("../ImageSharp.Tests/TestImages/Formats/Png/splash.png"); |
|
||||
pngCore = new CoreImage(pngStream); |
|
||||
pngStream.Position = 0; |
|
||||
pngDrawing = Image.FromStream(pngStream); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "System.Drawing Bmp")] |
|
||||
public void BmpSystemDrawing() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream()) |
|
||||
{ |
|
||||
bmpDrawing.Save(memoryStream, ImageFormat.Bmp); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "ImageSharp Bmp")] |
|
||||
public void BmpCore() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream()) |
|
||||
{ |
|
||||
bmpCore.SaveAsBmp(memoryStream); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "System.Drawing Gif")] |
|
||||
public void GifSystemDrawing() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream()) |
|
||||
{ |
|
||||
bmpDrawing.Save(memoryStream, ImageFormat.Gif); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "ImageSharp Gif")] |
|
||||
public void GifCore() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream()) |
|
||||
{ |
|
||||
bmpCore.SaveAsGif(memoryStream); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "System.Drawing Jpeg")] |
|
||||
public void JpegSystemDrawing() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream()) |
|
||||
{ |
|
||||
bmpDrawing.Save(memoryStream, ImageFormat.Jpeg); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "ImageSharp Jpeg")] |
|
||||
public void JpegCore() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream()) |
|
||||
{ |
|
||||
bmpCore.SaveAsJpeg(memoryStream); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "System.Drawing Png")] |
|
||||
public void PngSystemDrawing() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream()) |
|
||||
{ |
|
||||
bmpDrawing.Save(memoryStream, ImageFormat.Png); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "ImageSharp Png")] |
|
||||
public void PngCore() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream()) |
|
||||
{ |
|
||||
bmpCore.SaveAsPng(memoryStream); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,52 @@ |
|||||
|
// <copyright file="EncodeBmp.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Benchmarks.Image |
||||
|
{ |
||||
|
using System.Drawing; |
||||
|
using System.Drawing.Imaging; |
||||
|
using System.IO; |
||||
|
|
||||
|
using BenchmarkDotNet.Attributes; |
||||
|
using CoreImage = ImageSharp.Image; |
||||
|
|
||||
|
public class EncodeBmp |
||||
|
{ |
||||
|
// System.Drawing needs this.
|
||||
|
private Stream bmpStream; |
||||
|
private Image bmpDrawing; |
||||
|
private CoreImage bmpCore; |
||||
|
|
||||
|
[Setup] |
||||
|
public void ReadImages() |
||||
|
{ |
||||
|
if (this.bmpStream == null) |
||||
|
{ |
||||
|
this.bmpStream = File.OpenRead("../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp"); |
||||
|
this.bmpCore = new CoreImage(this.bmpStream); |
||||
|
this.bmpStream.Position = 0; |
||||
|
this.bmpDrawing = Image.FromStream(this.bmpStream); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Baseline = true, Description = "System.Drawing Bmp")] |
||||
|
public void JpegSystemDrawing() |
||||
|
{ |
||||
|
using (MemoryStream memoryStream = new MemoryStream()) |
||||
|
{ |
||||
|
this.bmpDrawing.Save(memoryStream, ImageFormat.Bmp); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Description = "ImageSharp Bmp")] |
||||
|
public void JpegCore() |
||||
|
{ |
||||
|
using (MemoryStream memoryStream = new MemoryStream()) |
||||
|
{ |
||||
|
this.bmpCore.SaveAsBmp(memoryStream); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,52 @@ |
|||||
|
// <copyright file="EncodeGif.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Benchmarks.Image |
||||
|
{ |
||||
|
using System.Drawing; |
||||
|
using System.Drawing.Imaging; |
||||
|
using System.IO; |
||||
|
|
||||
|
using BenchmarkDotNet.Attributes; |
||||
|
using CoreImage = ImageSharp.Image; |
||||
|
|
||||
|
public class EncodeGif |
||||
|
{ |
||||
|
// System.Drawing needs this.
|
||||
|
private Stream bmpStream; |
||||
|
private Image bmpDrawing; |
||||
|
private CoreImage bmpCore; |
||||
|
|
||||
|
[Setup] |
||||
|
public void ReadImages() |
||||
|
{ |
||||
|
if (this.bmpStream == null) |
||||
|
{ |
||||
|
this.bmpStream = File.OpenRead("../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp"); |
||||
|
this.bmpCore = new CoreImage(this.bmpStream); |
||||
|
this.bmpStream.Position = 0; |
||||
|
this.bmpDrawing = Image.FromStream(this.bmpStream); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Baseline = true, Description = "System.Drawing Gif")] |
||||
|
public void JpegSystemDrawing() |
||||
|
{ |
||||
|
using (MemoryStream memoryStream = new MemoryStream()) |
||||
|
{ |
||||
|
this.bmpDrawing.Save(memoryStream, ImageFormat.Gif); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Description = "ImageSharp Gif")] |
||||
|
public void JpegCore() |
||||
|
{ |
||||
|
using (MemoryStream memoryStream = new MemoryStream()) |
||||
|
{ |
||||
|
this.bmpCore.SaveAsGif(memoryStream); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,52 @@ |
|||||
|
// <copyright file="EncodeJpeg.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Benchmarks.Image |
||||
|
{ |
||||
|
using System.Drawing; |
||||
|
using System.Drawing.Imaging; |
||||
|
using System.IO; |
||||
|
|
||||
|
using BenchmarkDotNet.Attributes; |
||||
|
using CoreImage = ImageSharp.Image; |
||||
|
|
||||
|
public class EncodeJpeg |
||||
|
{ |
||||
|
// System.Drawing needs this.
|
||||
|
private Stream bmpStream; |
||||
|
private Image bmpDrawing; |
||||
|
private CoreImage bmpCore; |
||||
|
|
||||
|
[Setup] |
||||
|
public void ReadImages() |
||||
|
{ |
||||
|
if (this.bmpStream == null) |
||||
|
{ |
||||
|
this.bmpStream = File.OpenRead("../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp"); |
||||
|
this.bmpCore = new CoreImage(this.bmpStream); |
||||
|
this.bmpStream.Position = 0; |
||||
|
this.bmpDrawing = Image.FromStream(this.bmpStream); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Baseline = true, Description = "System.Drawing Jpeg")] |
||||
|
public void JpegSystemDrawing() |
||||
|
{ |
||||
|
using (MemoryStream memoryStream = new MemoryStream()) |
||||
|
{ |
||||
|
this.bmpDrawing.Save(memoryStream, ImageFormat.Jpeg); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Description = "ImageSharp Jpeg")] |
||||
|
public void JpegCore() |
||||
|
{ |
||||
|
using (MemoryStream memoryStream = new MemoryStream()) |
||||
|
{ |
||||
|
this.bmpCore.SaveAsJpeg(memoryStream); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,52 @@ |
|||||
|
// <copyright file="EncodePng.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Benchmarks.Image |
||||
|
{ |
||||
|
using System.Drawing; |
||||
|
using System.Drawing.Imaging; |
||||
|
using System.IO; |
||||
|
|
||||
|
using BenchmarkDotNet.Attributes; |
||||
|
using CoreImage = ImageSharp.Image; |
||||
|
|
||||
|
public class EncodePng |
||||
|
{ |
||||
|
// System.Drawing needs this.
|
||||
|
private Stream bmpStream; |
||||
|
private Image bmpDrawing; |
||||
|
private CoreImage bmpCore; |
||||
|
|
||||
|
[Setup] |
||||
|
public void ReadImages() |
||||
|
{ |
||||
|
if (this.bmpStream == null) |
||||
|
{ |
||||
|
this.bmpStream = File.OpenRead("../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp"); |
||||
|
this.bmpCore = new CoreImage(this.bmpStream); |
||||
|
this.bmpStream.Position = 0; |
||||
|
this.bmpDrawing = Image.FromStream(this.bmpStream); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Baseline = true, Description = "System.Drawing Png")] |
||||
|
public void JpegSystemDrawing() |
||||
|
{ |
||||
|
using (MemoryStream memoryStream = new MemoryStream()) |
||||
|
{ |
||||
|
this.bmpDrawing.Save(memoryStream, ImageFormat.Png); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Description = "ImageSharp Png")] |
||||
|
public void JpegCore() |
||||
|
{ |
||||
|
using (MemoryStream memoryStream = new MemoryStream()) |
||||
|
{ |
||||
|
this.bmpCore.SaveAsPng(memoryStream); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue