mirror of
https://github.com/aaru-dps/AaruBenchmark.git
synced 2025-12-16 19:24:36 +00:00
Add compression benchmarks.
This commit is contained in:
@@ -54,6 +54,14 @@
|
|||||||
<Content Include="data\flac.flac">
|
<Content Include="data\flac.flac">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
<None Remove="data\audio.bin"/>
|
||||||
|
<Content Include="data\audio.bin">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
<None Remove="data\data.bin"/>
|
||||||
|
<Content Include="data\data.bin">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -54,6 +54,19 @@ namespace AaruBenchmark
|
|||||||
public void DotNetZip() => Compression.DotNetZip.Gzip();
|
public void DotNetZip() => Compression.DotNetZip.Gzip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SimpleJob(RuntimeMoniker.Net60)]
|
||||||
|
public class CompressGzipBenchs
|
||||||
|
{
|
||||||
|
[Benchmark(Baseline = true)]
|
||||||
|
public void Aaru() => Compression.SharpCompress.CompressGzip();
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void Aaru6() => NetRuntime.CompressGzip();
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void DotNetZip() => Compression.DotNetZip.CompressGzip();
|
||||||
|
}
|
||||||
|
|
||||||
[SimpleJob(RuntimeMoniker.Net60)]
|
[SimpleJob(RuntimeMoniker.Net60)]
|
||||||
public class Bzip2Benchs
|
public class Bzip2Benchs
|
||||||
{
|
{
|
||||||
@@ -67,6 +80,19 @@ namespace AaruBenchmark
|
|||||||
public void AaruNative() => Compression.AaruNative.Bzip2();
|
public void AaruNative() => Compression.AaruNative.Bzip2();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SimpleJob(RuntimeMoniker.Net60)]
|
||||||
|
public class CompressBzip2Benchs
|
||||||
|
{
|
||||||
|
[Benchmark(Baseline = true)]
|
||||||
|
public void Aaru() => Compression.SharpCompress.CompressBzip2();
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void Aaru6() => DotNetZip.CompressBzip2();
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void AaruNative() => Compression.AaruNative.CompressBzip2();
|
||||||
|
}
|
||||||
|
|
||||||
public class LzipBenchs
|
public class LzipBenchs
|
||||||
{
|
{
|
||||||
[Benchmark(Baseline = true)]
|
[Benchmark(Baseline = true)]
|
||||||
@@ -76,6 +102,15 @@ namespace AaruBenchmark
|
|||||||
public void AaruNative() => Compression.AaruNative.Lzip();
|
public void AaruNative() => Compression.AaruNative.Lzip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class CompressLzipBenchs
|
||||||
|
{
|
||||||
|
[Benchmark(Baseline = true)]
|
||||||
|
public void SharpCompress() => Compression.SharpCompress.CompressLzip();
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void AaruNative() => Compression.AaruNative.CompressLzip();
|
||||||
|
}
|
||||||
|
|
||||||
public class LzmaBenchs
|
public class LzmaBenchs
|
||||||
{
|
{
|
||||||
[Benchmark(Baseline = true)]
|
[Benchmark(Baseline = true)]
|
||||||
@@ -85,6 +120,15 @@ namespace AaruBenchmark
|
|||||||
public void AaruNative() => Compression.AaruNative.Lzma();
|
public void AaruNative() => Compression.AaruNative.Lzma();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class CompressLzmaBenchs
|
||||||
|
{
|
||||||
|
[Benchmark(Baseline = true)]
|
||||||
|
public void SharpCompress() => Compression.SharpCompress.CompressLzma();
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void AaruNative() => Compression.AaruNative.CompressLzma();
|
||||||
|
}
|
||||||
|
|
||||||
[SimpleJob(RuntimeMoniker.Net60)]
|
[SimpleJob(RuntimeMoniker.Net60)]
|
||||||
public class FlacBenchs
|
public class FlacBenchs
|
||||||
{
|
{
|
||||||
@@ -95,6 +139,16 @@ namespace AaruBenchmark
|
|||||||
public void AaruNative() => Compression.AaruNative.Flac();
|
public void AaruNative() => Compression.AaruNative.Flac();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SimpleJob(RuntimeMoniker.Net60)]
|
||||||
|
public class CompressFlacBenchs
|
||||||
|
{
|
||||||
|
[Benchmark(Baseline = true)]
|
||||||
|
public void Aaru() => Compression.Aaru.CompressFlac();
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void AaruNative() => Compression.AaruNative.CompressFlac();
|
||||||
|
}
|
||||||
|
|
||||||
[SimpleJob(RuntimeMoniker.Net60)]
|
[SimpleJob(RuntimeMoniker.Net60)]
|
||||||
public class Adler32Benchs
|
public class Adler32Benchs
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -88,5 +88,44 @@ namespace AaruBenchmark.Compression
|
|||||||
if(crc != "dfbc99bb")
|
if(crc != "dfbc99bb")
|
||||||
throw new InvalidDataException("Incorrect decompressed checksum");
|
throw new InvalidDataException("Incorrect decompressed checksum");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CompressFlac()
|
||||||
|
{
|
||||||
|
var dataStream = new FileStream(Path.Combine(Program.Folder, "audio.bin"), FileMode.Open, FileAccess.Read);
|
||||||
|
byte[] decompressed = new byte[9633792];
|
||||||
|
dataStream.Read(decompressed, 0, decompressed.Length);
|
||||||
|
dataStream.Close();
|
||||||
|
byte[] backendBuffer = new byte[9633792];
|
||||||
|
|
||||||
|
var flakeWriterSettings = new EncoderSettings
|
||||||
|
{
|
||||||
|
PCM = AudioPCMConfig.RedBook,
|
||||||
|
DoMD5 = false,
|
||||||
|
BlockSize = 4608,
|
||||||
|
MinFixedOrder = 0,
|
||||||
|
MaxFixedOrder = 4,
|
||||||
|
MinLPCOrder = 1,
|
||||||
|
MaxLPCOrder = 32,
|
||||||
|
MaxPartitionOrder = 8,
|
||||||
|
StereoMethod = StereoMethod.Evaluate,
|
||||||
|
PredictionType = PredictionType.Search,
|
||||||
|
WindowMethod = WindowMethod.EvaluateN,
|
||||||
|
EstimationDepth = 5,
|
||||||
|
MinPrecisionSearch = 1,
|
||||||
|
MaxPrecisionSearch = 1,
|
||||||
|
TukeyParts = 0,
|
||||||
|
TukeyOverlap = 1.0,
|
||||||
|
TukeyP = 1.0,
|
||||||
|
AllowNonSubset = true
|
||||||
|
};
|
||||||
|
|
||||||
|
var flakeWriter = new AudioEncoder(flakeWriterSettings, "", new MemoryStream(backendBuffer))
|
||||||
|
{
|
||||||
|
DoSeekTable = false
|
||||||
|
};
|
||||||
|
|
||||||
|
var audioBuffer = new AudioBuffer(AudioPCMConfig.RedBook, decompressed, 2408448);
|
||||||
|
flakeWriter.Write(audioBuffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,17 +16,40 @@ namespace AaruBenchmark.Compression
|
|||||||
static extern int BZ2_bzBuffToBuffDecompress(byte[] dest, ref uint destLen, byte[] source, uint sourceLen,
|
static extern int BZ2_bzBuffToBuffDecompress(byte[] dest, ref uint destLen, byte[] source, uint sourceLen,
|
||||||
int small, int verbosity);
|
int small, int verbosity);
|
||||||
|
|
||||||
|
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||||
|
static extern int BZ2_bzBuffToBuffCompress(byte[] dest, ref uint destLen, byte[] source, uint sourceLen,
|
||||||
|
int blockSize100k, int verbosity, int workFactor);
|
||||||
|
|
||||||
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||||
static extern int lzip_decode_buffer(byte[] dst_buffer, int dst_size, byte[] src_buffer, int src_size);
|
static extern int lzip_decode_buffer(byte[] dst_buffer, int dst_size, byte[] src_buffer, int src_size);
|
||||||
|
|
||||||
|
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||||
|
static extern int lzip_encode_buffer(byte[] dst_buffer, int dst_size, byte[] src_buffer, int src_size,
|
||||||
|
int dictionary_size, int match_len_limit);
|
||||||
|
|
||||||
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||||
static extern int LzmaUncompress(byte[] dest, ref nuint destLen, byte[] src, ref nuint srcLen, byte[] props,
|
static extern int LzmaUncompress(byte[] dest, ref nuint destLen, byte[] src, ref nuint srcLen, byte[] props,
|
||||||
nuint propsSize);
|
nuint propsSize);
|
||||||
|
|
||||||
|
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||||
|
static extern int LzmaCompress(byte[] dest, ref nuint destLen, byte[] src, nuint srcLen, byte[] outProps,
|
||||||
|
ref nuint outPropsSize, int level, uint dictSize, int lc, int lp, int pb, int fb,
|
||||||
|
int numThreads);
|
||||||
|
|
||||||
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||||
static extern nuint flac_decode_redbook_buffer(byte[] dst_buffer, nuint dst_size, byte[] src_buffer,
|
static extern nuint flac_decode_redbook_buffer(byte[] dst_buffer, nuint dst_size, byte[] src_buffer,
|
||||||
nuint src_size);
|
nuint src_size);
|
||||||
|
|
||||||
|
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||||
|
static extern nuint flac_encode_redbook_buffer(byte[] dst_buffer, nuint dst_size, byte[] src_buffer,
|
||||||
|
nuint src_size, uint blocksize, int do_mid_side_stereo,
|
||||||
|
int loose_mid_side_stereo, string apodization,
|
||||||
|
uint qlp_coeff_precision, int do_qlp_coeff_prec_search,
|
||||||
|
int do_exhaustive_model_search,
|
||||||
|
uint min_residual_partition_order,
|
||||||
|
uint max_residual_partition_order, string application_id,
|
||||||
|
uint application_id_len);
|
||||||
|
|
||||||
public static void AppleRle()
|
public static void AppleRle()
|
||||||
{
|
{
|
||||||
const int bufferSize = 32768;
|
const int bufferSize = 32768;
|
||||||
@@ -100,6 +123,29 @@ namespace AaruBenchmark.Compression
|
|||||||
throw new InvalidDataException("Incorrect decompressed checksum");
|
throw new InvalidDataException("Incorrect decompressed checksum");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CompressBzip2()
|
||||||
|
{
|
||||||
|
var dataStream = new FileStream(Path.Combine(Program.Folder, "data.bin"), FileMode.Open, FileAccess.Read);
|
||||||
|
byte[] decompressed = new byte[8388608];
|
||||||
|
dataStream.Read(decompressed, 0, decompressed.Length);
|
||||||
|
dataStream.Close();
|
||||||
|
byte[] backendBuffer = new byte[8388608];
|
||||||
|
uint cmpSize = (uint)backendBuffer.Length;
|
||||||
|
|
||||||
|
BZ2_bzBuffToBuffCompress(backendBuffer, ref cmpSize, decompressed, (uint)decompressed.Length, 9, 0, 0);
|
||||||
|
|
||||||
|
/* This is just to test integrity, disabled for benchmarking
|
||||||
|
byte[] compressed = new byte[decompressed.Length];
|
||||||
|
uint dcmpSize = (uint)compressed.Length;
|
||||||
|
BZ2_bzBuffToBuffDecompress(compressed, ref dcmpSize, backendBuffer, cmpSize, 0, 0);
|
||||||
|
|
||||||
|
string newCrc = Crc32Context.Data(compressed, (uint)compressed.Length, out _);
|
||||||
|
|
||||||
|
if(newCrc != "954bf76e")
|
||||||
|
throw new InvalidDataException("Incorrect decompressed checksum");
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
public static void Lzip()
|
public static void Lzip()
|
||||||
{
|
{
|
||||||
const int bufferSize = 1048576;
|
const int bufferSize = 1048576;
|
||||||
@@ -124,6 +170,29 @@ namespace AaruBenchmark.Compression
|
|||||||
throw new InvalidDataException("Incorrect decompressed checksum");
|
throw new InvalidDataException("Incorrect decompressed checksum");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CompressLzip()
|
||||||
|
{
|
||||||
|
var dataStream = new FileStream(Path.Combine(Program.Folder, "data.bin"), FileMode.Open, FileAccess.Read);
|
||||||
|
byte[] decompressed = new byte[8388608];
|
||||||
|
dataStream.Read(decompressed, 0, decompressed.Length);
|
||||||
|
dataStream.Close();
|
||||||
|
byte[] backendBuffer = new byte[8388608];
|
||||||
|
int cmpSize = backendBuffer.Length;
|
||||||
|
|
||||||
|
cmpSize = lzip_encode_buffer(backendBuffer, cmpSize, decompressed, decompressed.Length, 106496, 32);
|
||||||
|
|
||||||
|
/* This is just to test integrity, disabled for benchmarking
|
||||||
|
byte[] compressed = new byte[decompressed.Length];
|
||||||
|
int dcmpSize = compressed.Length;
|
||||||
|
lzip_decode_buffer(compressed, dcmpSize, backendBuffer, cmpSize);
|
||||||
|
|
||||||
|
string newCrc = Crc32Context.Data(compressed, (uint)compressed.Length, out _);
|
||||||
|
|
||||||
|
if(newCrc != "954bf76e")
|
||||||
|
throw new InvalidDataException("Incorrect decompressed checksum");
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
public static void Lzma()
|
public static void Lzma()
|
||||||
{
|
{
|
||||||
const int bufferSize = 8388608;
|
const int bufferSize = 8388608;
|
||||||
@@ -157,6 +226,32 @@ namespace AaruBenchmark.Compression
|
|||||||
throw new InvalidDataException("Incorrect decompressed checksum");
|
throw new InvalidDataException("Incorrect decompressed checksum");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CompressLzma()
|
||||||
|
{
|
||||||
|
byte[] props = new byte[5];
|
||||||
|
var dataStream = new FileStream(Path.Combine(Program.Folder, "data.bin"), FileMode.Open, FileAccess.Read);
|
||||||
|
byte[] decompressed = new byte[8388608];
|
||||||
|
dataStream.Read(decompressed, 0, decompressed.Length);
|
||||||
|
dataStream.Close();
|
||||||
|
byte[] backendBuffer = new byte[8388608];
|
||||||
|
nuint cmpSize = (uint)backendBuffer.Length;
|
||||||
|
nuint propsSize = (uint)props.Length;
|
||||||
|
|
||||||
|
LzmaCompress(backendBuffer, ref cmpSize, decompressed, (nuint)decompressed.Length, props, ref propsSize, 9,
|
||||||
|
1048576, 3, 0, 2, 273, 2);
|
||||||
|
|
||||||
|
/* This is just to test integrity, disabled for benchmarking
|
||||||
|
byte[] compressed = new byte[decompressed.Length];
|
||||||
|
nuint dcmpSize = (uint)compressed.Length;
|
||||||
|
LzmaUncompress(compressed, ref dcmpSize, backendBuffer, ref cmpSize, props, propsSize);
|
||||||
|
|
||||||
|
string newCrc = Crc32Context.Data(compressed, (uint)compressed.Length, out _);
|
||||||
|
|
||||||
|
if(newCrc != "954bf76e")
|
||||||
|
throw new InvalidDataException("Incorrect decompressed checksum");
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
public static void Flac()
|
public static void Flac()
|
||||||
{
|
{
|
||||||
const int bufferSize = 9633792;
|
const int bufferSize = 9633792;
|
||||||
@@ -180,5 +275,19 @@ namespace AaruBenchmark.Compression
|
|||||||
if(crc != "dfbc99bb")
|
if(crc != "dfbc99bb")
|
||||||
throw new InvalidDataException("Incorrect decompressed checksum");
|
throw new InvalidDataException("Incorrect decompressed checksum");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CompressFlac()
|
||||||
|
{
|
||||||
|
var dataStream = new FileStream(Path.Combine(Program.Folder, "audio.bin"), FileMode.Open, FileAccess.Read);
|
||||||
|
byte[] decompressed = new byte[9633792];
|
||||||
|
dataStream.Read(decompressed, 0, decompressed.Length);
|
||||||
|
dataStream.Close();
|
||||||
|
byte[] backendBuffer = new byte[9633792];
|
||||||
|
nuint cmpSize = (uint)backendBuffer.Length;
|
||||||
|
|
||||||
|
flac_encode_redbook_buffer(backendBuffer, cmpSize, decompressed, (nuint)decompressed.Length, 4608, 1, 0,
|
||||||
|
"partial_tukey(0/1.0/1.0)", 0, 1, 0, 0, 8, "Aaru.Compression.Native.Tests",
|
||||||
|
(uint)"Aaru.Compression.Native.Tests".Length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,6 +35,53 @@ namespace AaruBenchmark.Compression
|
|||||||
str.Dispose();
|
str.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CompressGzip()
|
||||||
|
{
|
||||||
|
var dataStream = new FileStream(Path.Combine(Program.Folder, "data.bin"), FileMode.Open, FileAccess.Read);
|
||||||
|
byte[] decompressed = new byte[8388608];
|
||||||
|
dataStream.Read(decompressed, 0, decompressed.Length);
|
||||||
|
dataStream.Close();
|
||||||
|
|
||||||
|
var cmpMs = new MemoryStream();
|
||||||
|
|
||||||
|
Stream cmpStream = new GZipStream(cmpMs, CompressionMode.Compress, true);
|
||||||
|
cmpStream.Write(decompressed, 0, decompressed.Length);
|
||||||
|
cmpStream.Close();
|
||||||
|
cmpMs.Position = 0;
|
||||||
|
|
||||||
|
/* This is just to test integrity, disabled for benchmarking
|
||||||
|
Stream str = new GZipStream(cmpMs, CompressionMode.Decompress, true);
|
||||||
|
byte[] compressed = new byte[decompressed.Length];
|
||||||
|
int pos = 0;
|
||||||
|
int left = compressed.Length;
|
||||||
|
bool oneZero = false;
|
||||||
|
|
||||||
|
while(left > 0)
|
||||||
|
{
|
||||||
|
int done = str.Read(compressed, pos, left);
|
||||||
|
|
||||||
|
if(done == 0)
|
||||||
|
{
|
||||||
|
if(oneZero)
|
||||||
|
throw new IOException("Could not read the file!");
|
||||||
|
|
||||||
|
oneZero = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
left -= done;
|
||||||
|
pos += done;
|
||||||
|
}
|
||||||
|
|
||||||
|
str.Close();
|
||||||
|
str.Dispose();
|
||||||
|
|
||||||
|
string newCrc = Crc32Context.Data(compressed, (uint)compressed.Length, out _);
|
||||||
|
|
||||||
|
if(newCrc != "954bf76e")
|
||||||
|
throw new InvalidDataException("Incorrect decompressed checksum");
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
public static void Bzip2()
|
public static void Bzip2()
|
||||||
{
|
{
|
||||||
var _dataStream = new FileStream(Path.Combine(Program.Folder, "bzip2.bz2"), FileMode.Open, FileAccess.Read);
|
var _dataStream = new FileStream(Path.Combine(Program.Folder, "bzip2.bz2"), FileMode.Open, FileAccess.Read);
|
||||||
@@ -63,5 +110,52 @@ namespace AaruBenchmark.Compression
|
|||||||
str.Close();
|
str.Close();
|
||||||
str.Dispose();
|
str.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CompressBzip2()
|
||||||
|
{
|
||||||
|
var dataStream = new FileStream(Path.Combine(Program.Folder, "data.bin"), FileMode.Open, FileAccess.Read);
|
||||||
|
byte[] decompressed = new byte[8388608];
|
||||||
|
dataStream.Read(decompressed, 0, decompressed.Length);
|
||||||
|
dataStream.Close();
|
||||||
|
|
||||||
|
var cmpMs = new MemoryStream();
|
||||||
|
|
||||||
|
Stream cmpStream = new BZip2OutputStream(cmpMs, 9, true);
|
||||||
|
cmpStream.Write(decompressed, 0, decompressed.Length);
|
||||||
|
cmpStream.Close();
|
||||||
|
cmpMs.Position = 0;
|
||||||
|
|
||||||
|
/* This is just to test integrity, disabled for benchmarking
|
||||||
|
Stream str = new BZip2InputStream(cmpMs, true);
|
||||||
|
byte[] compressed = new byte[decompressed.Length];
|
||||||
|
int pos = 0;
|
||||||
|
int left = compressed.Length;
|
||||||
|
bool oneZero = false;
|
||||||
|
|
||||||
|
while(left > 0)
|
||||||
|
{
|
||||||
|
int done = str.Read(compressed, pos, left);
|
||||||
|
|
||||||
|
if(done == 0)
|
||||||
|
{
|
||||||
|
if(oneZero)
|
||||||
|
throw new IOException("Could not read the file!");
|
||||||
|
|
||||||
|
oneZero = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
left -= done;
|
||||||
|
pos += done;
|
||||||
|
}
|
||||||
|
|
||||||
|
str.Close();
|
||||||
|
str.Dispose();
|
||||||
|
|
||||||
|
string newCrc = Crc32Context.Data(compressed, (uint)compressed.Length, out _);
|
||||||
|
|
||||||
|
if(newCrc != "954bf76e")
|
||||||
|
throw new InvalidDataException("Incorrect decompressed checksum");
|
||||||
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,5 +33,52 @@ namespace AaruBenchmark.Compression
|
|||||||
str.Close();
|
str.Close();
|
||||||
str.Dispose();
|
str.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CompressGzip()
|
||||||
|
{
|
||||||
|
var dataStream = new FileStream(Path.Combine(Program.Folder, "data.bin"), FileMode.Open, FileAccess.Read);
|
||||||
|
byte[] decompressed = new byte[8388608];
|
||||||
|
dataStream.Read(decompressed, 0, decompressed.Length);
|
||||||
|
dataStream.Close();
|
||||||
|
|
||||||
|
var cmpMs = new MemoryStream();
|
||||||
|
|
||||||
|
Stream cmpStream = new GZipStream(cmpMs, CompressionMode.Compress, true);
|
||||||
|
cmpStream.Write(decompressed, 0, decompressed.Length);
|
||||||
|
cmpStream.Close();
|
||||||
|
cmpMs.Position = 0;
|
||||||
|
|
||||||
|
/* This is just to test integrity, disabled for benchmarking
|
||||||
|
Stream str = new GZipStream(cmpMs, CompressionMode.Decompress, true);
|
||||||
|
byte[] compressed = new byte[decompressed.Length];
|
||||||
|
int pos = 0;
|
||||||
|
int left = compressed.Length;
|
||||||
|
bool oneZero = false;
|
||||||
|
|
||||||
|
while(left > 0)
|
||||||
|
{
|
||||||
|
int done = str.Read(compressed, pos, left);
|
||||||
|
|
||||||
|
if(done == 0)
|
||||||
|
{
|
||||||
|
if(oneZero)
|
||||||
|
throw new IOException("Could not read the file!");
|
||||||
|
|
||||||
|
oneZero = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
left -= done;
|
||||||
|
pos += done;
|
||||||
|
}
|
||||||
|
|
||||||
|
str.Close();
|
||||||
|
str.Dispose();
|
||||||
|
|
||||||
|
string newCrc = Crc32Context.Data(compressed, (uint)compressed.Length, out _);
|
||||||
|
|
||||||
|
if(newCrc != "954bf76e")
|
||||||
|
throw new InvalidDataException("Incorrect decompressed checksum");
|
||||||
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,6 +39,50 @@ namespace AaruBenchmark.Compression
|
|||||||
str.Dispose();
|
str.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CompressGzip()
|
||||||
|
{
|
||||||
|
var dataStream = new FileStream(Path.Combine(Program.Folder, "data.bin"), FileMode.Open, FileAccess.Read);
|
||||||
|
byte[] decompressed = new byte[8388608];
|
||||||
|
dataStream.Read(decompressed, 0, decompressed.Length);
|
||||||
|
dataStream.Close();
|
||||||
|
byte[] backendBuffer = new byte[8388608];
|
||||||
|
|
||||||
|
Stream cmpStream = new GZipStream(new MemoryStream(backendBuffer), CompressionMode.Compress,
|
||||||
|
CompressionLevel.Level9);
|
||||||
|
|
||||||
|
cmpStream.Write(decompressed, 0, decompressed.Length);
|
||||||
|
cmpStream.Close();
|
||||||
|
|
||||||
|
/* This is just to test integrity, disabled for benchmarking
|
||||||
|
Stream str = new GZipStream(new MemoryStream(backendBuffer), CompressionMode.Decompress);
|
||||||
|
byte[] compressed = new byte[decompressed.Length];
|
||||||
|
int pos = 0;
|
||||||
|
int left = compressed.Length;
|
||||||
|
bool oneZero = false;
|
||||||
|
|
||||||
|
while(left > 0)
|
||||||
|
{
|
||||||
|
int done = str.Read(compressed, pos, left);
|
||||||
|
|
||||||
|
if(done == 0)
|
||||||
|
{
|
||||||
|
if(oneZero)
|
||||||
|
throw new IOException("Could not read the file!");
|
||||||
|
|
||||||
|
oneZero = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
left -= done;
|
||||||
|
pos += done;
|
||||||
|
}
|
||||||
|
|
||||||
|
string newCrc = Crc32Context.Data(compressed, (uint)compressed.Length, out _);
|
||||||
|
|
||||||
|
if(newCrc != "954bf76e")
|
||||||
|
throw new InvalidDataException("Incorrect decompressed checksum");
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
public static void Bzip2()
|
public static void Bzip2()
|
||||||
{
|
{
|
||||||
var _dataStream = new FileStream(Path.Combine(Program.Folder, "bzip2.bz2"), FileMode.Open, FileAccess.Read);
|
var _dataStream = new FileStream(Path.Combine(Program.Folder, "bzip2.bz2"), FileMode.Open, FileAccess.Read);
|
||||||
@@ -68,6 +112,48 @@ namespace AaruBenchmark.Compression
|
|||||||
str.Dispose();
|
str.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CompressBzip2()
|
||||||
|
{
|
||||||
|
var dataStream = new FileStream(Path.Combine(Program.Folder, "data.bin"), FileMode.Open, FileAccess.Read);
|
||||||
|
byte[] decompressed = new byte[8388608];
|
||||||
|
dataStream.Read(decompressed, 0, decompressed.Length);
|
||||||
|
dataStream.Close();
|
||||||
|
byte[] backendBuffer = new byte[8388608];
|
||||||
|
|
||||||
|
Stream cmpStream = new BZip2Stream(new MemoryStream(backendBuffer), CompressionMode.Compress, true);
|
||||||
|
cmpStream.Write(decompressed, 0, decompressed.Length);
|
||||||
|
cmpStream.Close();
|
||||||
|
|
||||||
|
/* This is just to test integrity, disabled for benchmarking
|
||||||
|
Stream str = new BZip2Stream(new MemoryStream(backendBuffer), CompressionMode.Decompress, false);
|
||||||
|
byte[] compressed = new byte[decompressed.Length];
|
||||||
|
int pos = 0;
|
||||||
|
int left = compressed.Length;
|
||||||
|
bool oneZero = false;
|
||||||
|
|
||||||
|
while(left > 0)
|
||||||
|
{
|
||||||
|
int done = str.Read(compressed, pos, left);
|
||||||
|
|
||||||
|
if(done == 0)
|
||||||
|
{
|
||||||
|
if(oneZero)
|
||||||
|
throw new IOException("Could not read the file!");
|
||||||
|
|
||||||
|
oneZero = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
left -= done;
|
||||||
|
pos += done;
|
||||||
|
}
|
||||||
|
|
||||||
|
string newCrc = Crc32Context.Data(compressed, (uint)compressed.Length, out _);
|
||||||
|
|
||||||
|
if(newCrc != "954bf76e")
|
||||||
|
throw new InvalidDataException("Incorrect decompressed checksum");
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
public static void ADC()
|
public static void ADC()
|
||||||
{
|
{
|
||||||
var _dataStream = new FileStream(Path.Combine(Program.Folder, "adc.bin"), FileMode.Open, FileAccess.Read);
|
var _dataStream = new FileStream(Path.Combine(Program.Folder, "adc.bin"), FileMode.Open, FileAccess.Read);
|
||||||
@@ -136,6 +222,48 @@ namespace AaruBenchmark.Compression
|
|||||||
throw new InvalidDataException("Incorrect decompressed checksum");
|
throw new InvalidDataException("Incorrect decompressed checksum");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CompressLzip()
|
||||||
|
{
|
||||||
|
var dataStream = new FileStream(Path.Combine(Program.Folder, "data.bin"), FileMode.Open, FileAccess.Read);
|
||||||
|
byte[] decompressed = new byte[8388608];
|
||||||
|
dataStream.Read(decompressed, 0, decompressed.Length);
|
||||||
|
dataStream.Close();
|
||||||
|
byte[] backendBuffer = new byte[8388608];
|
||||||
|
|
||||||
|
Stream cmpStream = new LZipStream(new MemoryStream(backendBuffer), CompressionMode.Compress);
|
||||||
|
cmpStream.Write(decompressed, 0, decompressed.Length);
|
||||||
|
cmpStream.Close();
|
||||||
|
|
||||||
|
/* This is just to test integrity, disabled for benchmarking
|
||||||
|
Stream str = new LZipStream(new MemoryStream(backendBuffer), CompressionMode.Decompress);
|
||||||
|
byte[] compressed = new byte[decompressed.Length];
|
||||||
|
int pos = 0;
|
||||||
|
int left = compressed.Length;
|
||||||
|
bool oneZero = false;
|
||||||
|
|
||||||
|
while(left > 0)
|
||||||
|
{
|
||||||
|
int done = str.Read(compressed, pos, left);
|
||||||
|
|
||||||
|
if(done == 0)
|
||||||
|
{
|
||||||
|
if(oneZero)
|
||||||
|
throw new IOException("Could not read the file!");
|
||||||
|
|
||||||
|
oneZero = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
left -= done;
|
||||||
|
pos += done;
|
||||||
|
}
|
||||||
|
|
||||||
|
string newCrc = Crc32Context.Data(compressed, (uint)compressed.Length, out _);
|
||||||
|
|
||||||
|
if(newCrc != "954bf76e")
|
||||||
|
throw new InvalidDataException("Incorrect decompressed checksum");
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
public static void Lzma()
|
public static void Lzma()
|
||||||
{
|
{
|
||||||
var _dataStream = new FileStream(Path.Combine(Program.Folder, "lzma.bin"), FileMode.Open, FileAccess.Read);
|
var _dataStream = new FileStream(Path.Combine(Program.Folder, "lzma.bin"), FileMode.Open, FileAccess.Read);
|
||||||
@@ -174,5 +302,52 @@ namespace AaruBenchmark.Compression
|
|||||||
if(crc != "954bf76e")
|
if(crc != "954bf76e")
|
||||||
throw new InvalidDataException("Incorrect decompressed checksum");
|
throw new InvalidDataException("Incorrect decompressed checksum");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CompressLzma()
|
||||||
|
{
|
||||||
|
var dataStream = new FileStream(Path.Combine(Program.Folder, "data.bin"), FileMode.Open, FileAccess.Read);
|
||||||
|
byte[] decompressed = new byte[8388608];
|
||||||
|
dataStream.Read(decompressed, 0, decompressed.Length);
|
||||||
|
dataStream.Close();
|
||||||
|
byte[] backendBuffer = new byte[8388608];
|
||||||
|
|
||||||
|
var cmpStream = new LzmaStream(new LzmaEncoderProperties(true, 1048576, 273), false,
|
||||||
|
new MemoryStream(backendBuffer));
|
||||||
|
|
||||||
|
byte[] propertiesArray = new byte[cmpStream.Properties.Length];
|
||||||
|
cmpStream.Properties.CopyTo(propertiesArray, 0);
|
||||||
|
|
||||||
|
cmpStream.Write(decompressed, 0, decompressed.Length);
|
||||||
|
cmpStream.Close();
|
||||||
|
|
||||||
|
/* This is just to test integrity, disabled for benchmarking
|
||||||
|
Stream str = new LzmaStream(propertiesArray, new MemoryStream(backendBuffer));
|
||||||
|
byte[] compressed = new byte[decompressed.Length];
|
||||||
|
int pos = 0;
|
||||||
|
int left = compressed.Length;
|
||||||
|
bool oneZero = false;
|
||||||
|
|
||||||
|
while(left > 0)
|
||||||
|
{
|
||||||
|
int done = str.Read(compressed, pos, left);
|
||||||
|
|
||||||
|
if(done == 0)
|
||||||
|
{
|
||||||
|
if(oneZero)
|
||||||
|
throw new IOException("Could not read the file!");
|
||||||
|
|
||||||
|
oneZero = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
left -= done;
|
||||||
|
pos += done;
|
||||||
|
}
|
||||||
|
|
||||||
|
string newCrc = Crc32Context.Data(compressed, (uint)compressed.Length, out _);
|
||||||
|
|
||||||
|
if(newCrc != "954bf76e")
|
||||||
|
throw new InvalidDataException("Incorrect decompressed checksum");
|
||||||
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,11 @@ namespace AaruBenchmark
|
|||||||
BenchmarkRunner.Run<LzipBenchs>(config);
|
BenchmarkRunner.Run<LzipBenchs>(config);
|
||||||
BenchmarkRunner.Run<LzmaBenchs>(config);
|
BenchmarkRunner.Run<LzmaBenchs>(config);
|
||||||
BenchmarkRunner.Run<FlacBenchs>(config);
|
BenchmarkRunner.Run<FlacBenchs>(config);
|
||||||
|
BenchmarkRunner.Run<CompressGzipBenchs>(config);
|
||||||
|
BenchmarkRunner.Run<CompressBzip2Benchs>(config);
|
||||||
|
BenchmarkRunner.Run<CompressLzipBenchs>(config);
|
||||||
|
BenchmarkRunner.Run<CompressLzmaBenchs>(config);
|
||||||
|
BenchmarkRunner.Run<CompressFlacBenchs>(config);
|
||||||
BenchmarkRunner.Run<Adler32Benchs>(config);
|
BenchmarkRunner.Run<Adler32Benchs>(config);
|
||||||
BenchmarkRunner.Run<Crc16CcittBenchs>(config);
|
BenchmarkRunner.Run<Crc16CcittBenchs>(config);
|
||||||
BenchmarkRunner.Run<Crc16Benchs>(config);
|
BenchmarkRunner.Run<Crc16Benchs>(config);
|
||||||
|
|||||||
BIN
AaruBenchmark/data/audio.bin
Normal file
BIN
AaruBenchmark/data/audio.bin
Normal file
Binary file not shown.
BIN
AaruBenchmark/data/data.bin
Normal file
BIN
AaruBenchmark/data/data.bin
Normal file
Binary file not shown.
Reference in New Issue
Block a user