-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from jzebedee/zero_alloc_sais
Add Go SAIS suffix sorter
- Loading branch information
Showing
14 changed files
with
1,264 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,76 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Diagnosers; | ||
using BenchmarkDotNet.Engines; | ||
using DeltaQ.SuffixSorting; | ||
using DeltaQ.SuffixSorting.LibDivSufSort; | ||
using DeltaQ.SuffixSorting.SAIS; | ||
|
||
namespace DeltaQ.Benchmarks | ||
{ | ||
//[MemoryDiagnoser] | ||
[MemoryDiagnoser] | ||
[HardwareCounters(HardwareCounter.BranchInstructions, HardwareCounter.BranchMispredictions)] | ||
public class SuffixSortingBenchmarks | ||
{ | ||
private static byte[] GetOwnedRandomBuffer(int size) | ||
{ | ||
var rand = new Random(63 * 13 * 63 * 13); | ||
var buf = new byte[size]; | ||
rand.NextBytes(buf); | ||
return buf; | ||
} | ||
|
||
private const string AbsoluteAssetsPath = @"assets/"; | ||
public static IEnumerable<object[]> Assets { get; } = Directory.EnumerateFiles(AbsoluteAssetsPath) | ||
.Select(file => new object[] { Path.GetFileName(file), File.ReadAllBytes(file) }) | ||
.Select(file => new { filename = Path.GetFileName(file), contents = File.ReadAllBytes(file) }) | ||
.Select(a => new object[] { a.filename, a.contents }) | ||
.ToArray(); | ||
|
||
private static readonly ISuffixSort LDSS = new LibDivSufSort(); | ||
private static readonly ISuffixSort SAIS = new SAIS(); | ||
|
||
[ArgumentsSource(nameof(Assets))] | ||
[Benchmark] | ||
public void ldss(string name, byte[] asset) | ||
public static IEnumerable<int> Sizes | ||
{ | ||
LDSS.Sort(asset).Dispose(); | ||
get | ||
{ | ||
yield return 0; | ||
yield return 1; | ||
yield return 2; | ||
yield return 4; | ||
yield return 8; | ||
yield return 16; | ||
yield return 32; | ||
yield return 64; | ||
yield return 128; | ||
yield return 256; | ||
yield return 512; | ||
yield return 1024; | ||
yield return 2048; | ||
yield return 4096; | ||
yield return 8192; | ||
yield return 16384; | ||
yield return 32768; | ||
for (int i = 64; i <= 1024; i += 64) | ||
{ | ||
yield return i * 1024; | ||
} | ||
} | ||
} | ||
public static IEnumerable<object[]> Randoms { get; } = Sizes | ||
.Select(i => new { size = i, asset = GetOwnedRandomBuffer(i) }) | ||
.Select(a => new object[] { a.size.ToString(), a.asset }) | ||
.ToArray(); | ||
|
||
private static readonly ISuffixSort GoSAIS = new GoSAIS(); | ||
private static readonly ISuffixSort SAIS = new SAIS(); | ||
private static readonly ISuffixSort LDSS = new LibDivSufSort(); | ||
|
||
[ArgumentsSource(nameof(Assets))] | ||
[ArgumentsSource(nameof(Randoms))] | ||
[Benchmark(Baseline = true)] | ||
public void sais(string name, byte[] asset) | ||
{ | ||
SAIS.Sort(asset).Dispose(); | ||
} | ||
public void sais(string name, byte[] asset) => SAIS.Sort(asset).Dispose(); | ||
|
||
[ArgumentsSource(nameof(Randoms))] | ||
[Benchmark] | ||
public void go_sais(string name, byte[] asset) => GoSAIS.Sort(asset).Dispose(); | ||
|
||
[ArgumentsSource(nameof(Randoms))] | ||
[Benchmark] | ||
public void ldss(string name, byte[] asset) => LDSS.Sort(asset).Dispose(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
afl-tmin -i findings/crashes.2022-01-07-13\:56\:25/id:000002,sig:02,src:000128,op:arith8,pos:91,val:+27 -o crash-force-sais-tmp-alloc -t 5000 -m 10000 -- dotnet bin/Release/net6.0/DeltaQ.CommandLine.dll fuzz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.