Implement native benchmark for Apple RLE.

This commit is contained in:
2021-10-17 01:22:59 +01:00
parent bc2a7acea5
commit 92dad2f0f0
4 changed files with 43 additions and 0 deletions

View File

@@ -34,6 +34,10 @@
<Content Include="data\teledisk_lzh.bin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="libAaru.Compression.Native.so"/>
<Content Include="libAaru.Compression.Native.so">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>

View File

@@ -13,6 +13,9 @@ namespace AaruBenchmark
[Benchmark]
public void Aaru6() => Aaru6Compressions.AppleRle();
[Benchmark]
public void AaruNative() => Compression.AaruNative.AppleRle();
}
[SimpleJob(RuntimeMoniker.Net60)]

View File

@@ -0,0 +1,36 @@
using System.IO;
using System.Runtime.InteropServices;
using Aaru6.Checksums;
namespace AaruBenchmark.Compression
{
public class AaruNative
{
[DllImport("libAaru.Compression.Native", SetLastError = true)]
static extern int apple_rle_decode_buffer(byte[] dst_buffer, int dst_size, byte[] src_buffer, int src_size);
public static void AppleRle()
{
const int bufferSize = 32768;
byte[] input = new byte[1102];
var fs = new FileStream(Path.Combine(Program.Folder, "apple_rle.bin"), FileMode.Open, FileAccess.Read);
fs.Read(input, 0, input.Length);
fs.Close();
fs.Dispose();
byte[] output = new byte[bufferSize];
int realSize = apple_rle_decode_buffer(output, output.Length, input, input.Length);
if(realSize != 20960)
throw new InvalidDataException("Incorrect decompressed size");
string crc = Crc32Context.Data(output, (uint)realSize, out _);
if(crc != "3525ef06")
throw new InvalidDataException("Incorrect decompressed checksum");
}
}
}

Binary file not shown.