-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Linq; | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace GeometryDashAPI.Benchmarks.Benchmarks; | ||
|
||
[MemoryDiagnoser] | ||
public class XorBenchmark | ||
{ | ||
private static Random random = new(123); | ||
private byte[] array = Enumerable.Range(0, 1000).Select(x => (byte)random.Next(byte.MaxValue)).ToArray(); | ||
|
||
[Benchmark] | ||
public void SimdXor() | ||
{ | ||
Crypt.InlineXor(array, 11); | ||
} | ||
|
||
[Benchmark] | ||
public void NaiveXor() | ||
{ | ||
Crypt.NaiveXor(array, 11); | ||
} | ||
|
||
[Benchmark] | ||
public byte[] OldXor() | ||
{ | ||
return Crypt.XOR(array, 11); | ||
} | ||
} |
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,23 @@ | ||
using System; | ||
using System.Linq; | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
|
||
namespace GeometryDashAPI.Tests; | ||
|
||
[TestFixture] | ||
public class CryptTests | ||
{ | ||
[Test] | ||
public void InlineXor() | ||
{ | ||
var random = new Random(123); | ||
var data = Enumerable.Range(0, 100).Select(_ => (byte)random.Next(byte.MaxValue)).ToArray(); | ||
var expected = (byte[])data.Clone(); | ||
|
||
Crypt.NaiveXor(expected, 11); | ||
Crypt.InlineXor(data.AsSpan(), 11); | ||
|
||
data.Should().BeEquivalentTo(expected); | ||
} | ||
} |
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