diff --git a/AaruBenchmark/AaruBenchmark.csproj b/AaruBenchmark/AaruBenchmark.csproj index d7bcd73..142cb2d 100644 --- a/AaruBenchmark/AaruBenchmark.csproj +++ b/AaruBenchmark/AaruBenchmark.csproj @@ -42,6 +42,10 @@ Always + + + Always + diff --git a/AaruBenchmark/Benchs.cs b/AaruBenchmark/Benchs.cs index 46a8162..2f4d818 100644 --- a/AaruBenchmark/Benchs.cs +++ b/AaruBenchmark/Benchs.cs @@ -67,6 +67,15 @@ namespace AaruBenchmark public void AaruNative() => Compression.AaruNative.Bzip2(); } + public class LzipBenchs + { + [Benchmark(Baseline = true)] + public void SharpCompress() => Compression.SharpCompress.Lzip(); + + [Benchmark] + public void AaruNative() => Compression.AaruNative.Lzip(); + } + [SimpleJob(RuntimeMoniker.Net60)] public class Adler32Benchs { diff --git a/AaruBenchmark/Compression/AaruNative.cs b/AaruBenchmark/Compression/AaruNative.cs index 2937c01..dcdd494 100644 --- a/AaruBenchmark/Compression/AaruNative.cs +++ b/AaruBenchmark/Compression/AaruNative.cs @@ -16,6 +16,9 @@ namespace AaruBenchmark.Compression static extern int BZ2_bzBuffToBuffDecompress(byte[] dest, ref uint destLen, byte[] source, uint sourceLen, int small, int verbosity); + [DllImport("libAaru.Compression.Native", SetLastError = true)] + static extern int lzip_decode_buffer(byte[] dst_buffer, int dst_size, byte[] src_buffer, int src_size); + public static void AppleRle() { const int bufferSize = 32768; @@ -88,5 +91,29 @@ namespace AaruBenchmark.Compression if(crc != "c64059c0") throw new InvalidDataException("Incorrect decompressed checksum"); } + + public static void Lzip() + { + const int bufferSize = 1048576; + byte[] input = new byte[1062874]; + + var fs = new FileStream(Path.Combine(Program.Folder, "lzip.lz"), FileMode.Open, FileAccess.Read); + + fs.Read(input, 0, input.Length); + fs.Close(); + fs.Dispose(); + + byte[] output = new byte[bufferSize]; + + int realSize = lzip_decode_buffer(output, output.Length, input, input.Length); + + if(realSize != 1048576) + throw new InvalidDataException("Incorrect decompressed size"); + + string crc = Crc32Context.Data(output, (uint)realSize, out _); + + if(crc != "c64059c0") + throw new InvalidDataException("Incorrect decompressed checksum"); + } } } \ No newline at end of file diff --git a/AaruBenchmark/Compression/SharpCompress.cs b/AaruBenchmark/Compression/SharpCompress.cs index 1752efb..71db76a 100644 --- a/AaruBenchmark/Compression/SharpCompress.cs +++ b/AaruBenchmark/Compression/SharpCompress.cs @@ -4,6 +4,7 @@ using SharpCompress.Compressors; using SharpCompress.Compressors.ADC; using SharpCompress.Compressors.BZip2; using SharpCompress.Compressors.Deflate; +using SharpCompress.Compressors.LZMA; namespace AaruBenchmark.Compression { @@ -100,5 +101,39 @@ namespace AaruBenchmark.Compression if(crc != "5a5a7388") throw new InvalidDataException("Incorrect decompressed checksum"); } + + public static void Lzip() + { + var _dataStream = new FileStream(Path.Combine(Program.Folder, "lzip.lz"), FileMode.Open, FileAccess.Read); + Stream str = new LZipStream(_dataStream, CompressionMode.Decompress); + byte[] compressed = new byte[1048576]; + int pos = 0; + int left = 1048576; + 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 crc = Crc32Context.Data(compressed, 1048576, out _); + + if(crc != "c64059c0") + throw new InvalidDataException("Incorrect decompressed checksum"); + } } } \ No newline at end of file diff --git a/AaruBenchmark/Program.cs b/AaruBenchmark/Program.cs index b25dd24..52a86d5 100644 --- a/AaruBenchmark/Program.cs +++ b/AaruBenchmark/Program.cs @@ -18,6 +18,7 @@ namespace AaruBenchmark BenchmarkRunner.Run(config); BenchmarkRunner.Run(config); BenchmarkRunner.Run(config); + BenchmarkRunner.Run(config); BenchmarkRunner.Run(config); BenchmarkRunner.Run(config); BenchmarkRunner.Run(config); diff --git a/AaruBenchmark/data/lzip.lz b/AaruBenchmark/data/lzip.lz new file mode 100644 index 0000000..a1675ee Binary files /dev/null and b/AaruBenchmark/data/lzip.lz differ diff --git a/Benchmarks.ods b/Benchmarks.ods index 6abd640..e1ef031 100644 Binary files a/Benchmarks.ods and b/Benchmarks.ods differ