Skip to content

Commit

Permalink
SixLabors#12 Add benchmarks for big tiff files
Browse files Browse the repository at this point in the history
  • Loading branch information
IldarKhayrutdinov committed Aug 11, 2019
1 parent 72e1afd commit 96d9158
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
108 changes: 108 additions & 0 deletions tests/ImageSharp.Benchmarks/Codecs/DecodeTiffBig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//Copyright(c) Six Labors and contributors.
//Licensed under the Apache License, Version 2.0.

using System.IO;

using BenchmarkDotNet.Attributes;

using SixLabors.ImageSharp.PixelFormats;

using CoreImage = SixLabors.ImageSharp.Image;
using CoreSize = SixLabors.Primitives.Size;

namespace SixLabors.ImageSharp.Benchmarks.Codecs
{
[Config(typeof(Config.LongClr))]
public class DecodeTiffBig : BenchmarkBase
{
private byte[] grayscale_uncompressed;

private byte[] palette_uncompressed;

private byte[] rgb_deflate;

////private byte[] rgb_jpeg;

private byte[] rgb_lzw;

private byte[] rgb_packbits;

private byte[] rgb_uncompressed;

[GlobalSetup]
public void ReadImages()
{
if (this.grayscale_uncompressed == null)
{
string path = @"C:\Work\GitHub\SixLabors.ImageSharp\tests\ImageSharp.Tests\TestImages\Formats\Tiff\";
this.grayscale_uncompressed = File.ReadAllBytes(path + "jpeg444_big_grayscale_uncompressed.tiff");
this.palette_uncompressed = File.ReadAllBytes(path + "jpeg444_big_palette_uncompressed.tiff");
this.rgb_deflate = File.ReadAllBytes(path + "jpeg444_big_rgb_deflate.tiff");
////this.rgb_jpeg = File.ReadAllBytes(path + "jpeg444_big_rgb_jpeg.tiff");
this.rgb_lzw = File.ReadAllBytes(path + "jpeg444_big_rgb_lzw.tiff");
this.rgb_packbits = File.ReadAllBytes(path + "jpeg444_big_rgb_packbits.tiff");
this.rgb_uncompressed = File.ReadAllBytes(path + "jpeg444_big_rgb_uncompressed.tiff");
}
}

[Benchmark(Description = "Tiff grayscale_uncompressed")]
public CoreSize GrayscaleUncompressed()
{
using (MemoryStream ms = new MemoryStream(this.grayscale_uncompressed))
using (Image<Rgba32> image = CoreImage.Load<Rgba32>(ms))
{
return new CoreSize(image.Width, image.Height);
}
}

[Benchmark(Description = "Tiff palette_uncompressed")]
public CoreSize PaletteUncompressed()
{
using (MemoryStream ms = new MemoryStream(this.palette_uncompressed))
using (Image<Rgba32> image = CoreImage.Load<Rgba32>(ms))
{
return new CoreSize(image.Width, image.Height);
}
}

[Benchmark(Description = "Tiff rgb_deflate")]
public CoreSize RgbDeflate()
{
using (MemoryStream ms = new MemoryStream(this.rgb_deflate))
using (Image<Rgba32> image = CoreImage.Load<Rgba32>(ms))
{
return new CoreSize(image.Width, image.Height);
}
}

[Benchmark(Description = "Tiff rgb_lzw")]
public CoreSize RgbLzw()
{
using (MemoryStream ms = new MemoryStream(this.rgb_lzw))
using (Image<Rgba32> image = CoreImage.Load<Rgba32>(ms))
{
return new CoreSize(image.Width, image.Height);
}
}

[Benchmark(Description = "Tiff rgb_packbits")]
public CoreSize RgbPackbits()
{
using (MemoryStream ms = new MemoryStream(this.rgb_packbits))
using (Image<Rgba32> image = CoreImage.Load<Rgba32>(ms))
{
return new CoreSize(image.Width, image.Height);
}
}

[Benchmark(Description = "Tiff rgb_uncompressed")]
public CoreSize RgbUncompressed()
{
using (MemoryStream ms = new MemoryStream(this.rgb_uncompressed))
using (Image<Rgba32> image = CoreImage.Load<Rgba32>(ms))
{
return new CoreSize(image.Width, image.Height);
}
}
}
}
11 changes: 11 additions & 0 deletions tests/ImageSharp.Benchmarks/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,16 @@ public ShortClr()
);
}
}

public class LongClr : Config
{
public LongClr()
{
this.Add(
Job.Clr.WithLaunchCount(1).WithWarmupCount(3).WithTargetCount(5),
Job.Core.WithLaunchCount(1).WithWarmupCount(3).WithTargetCount(5)
);
}
}
}
}
1 change: 1 addition & 0 deletions tests/ImageSharp.Tests/TestImages/Formats/Tiff/gen.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
powershell -executionpolicy RemoteSigned -file gen_big.ps1
12 changes: 12 additions & 0 deletions tests/ImageSharp.Tests/TestImages/Formats/Tiff/gen_big.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$Gm_Exe = "C:\Program Files\ImageMagick-7.0.8-Q16\magick.exe"
$Source_Image = ".\jpeg444_big.jpg"
$Output_Prefix = ".\jpeg444_big"

& $Gm_Exe convert $Source_Image -compress None -type TrueColor $Output_Prefix"_rgb_uncompressed.tiff"
& $Gm_Exe convert $Source_Image -compress LZW -type TrueColor $Output_Prefix"_rgb_lzw.tiff"
& $Gm_Exe convert $Source_Image -compress RLE -type TrueColor $Output_Prefix"_rgb_packbits.tiff"
& $Gm_Exe convert $Source_Image -compress JPEG -type TrueColor $Output_Prefix"_rgb_jpeg.tiff"
& $Gm_Exe convert $Source_Image -compress Zip -type TrueColor $Output_Prefix"_rgb_deflate.tiff"

& $Gm_Exe convert $Source_Image -compress None -type Grayscale $Output_Prefix"_grayscale_uncompressed.tiff"
& $Gm_Exe convert $Source_Image -compress None -colors 256 $Output_Prefix"_palette_uncompressed.tiff"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 96d9158

Please sign in to comment.