-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'HF_Echidna' into fix.overflow-in-substr
- Loading branch information
Showing
182 changed files
with
3,911 additions
and
711 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// Benchmarks.Hash.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using Neo.Cryptography; | ||
using Neo.Extensions; | ||
using System.Diagnostics; | ||
using System.IO.Hashing; | ||
using System.Text; | ||
|
||
namespace Neo.Benchmark; | ||
|
||
public class Benchmarks_Hash | ||
{ | ||
// 256 KiB | ||
static readonly byte[] data = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat("Hello, World!^_^", 16 * 1024))); | ||
|
||
static readonly byte[] hash = "9182abedfbb9b18d81a05d8bcb45489e7daa2858".HexToBytes(); | ||
|
||
[Benchmark] | ||
public void RIPEMD160_ComputeHash() | ||
{ | ||
using var ripemd160 = new RIPEMD160Managed(); | ||
var result = ripemd160.ComputeHash(data); | ||
Debug.Assert(result.SequenceEqual(hash)); | ||
} | ||
|
||
[Benchmark] | ||
public void XxHash32_HashToUInt32() | ||
{ | ||
var result = XxHash32.HashToUInt32(data); | ||
Debug.Assert(result == 682967318u); | ||
} | ||
|
||
[Benchmark] | ||
public void XxHash3_HashToUInt64() | ||
{ | ||
var result = (uint)XxHash3.HashToUInt64(data); | ||
Debug.Assert(result == 1389469485u); | ||
} | ||
|
||
[Benchmark] | ||
public void Murmur32_HashToUInt32() | ||
{ | ||
var result = data.Murmur32(0); | ||
Debug.Assert(result == 3731881930u); | ||
} | ||
} |
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
165 changes: 165 additions & 0 deletions
165
benchmarks/Neo.Extensions.Benchmarks/Benchmark.ByteArrayComparer.cs
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,165 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// Benchmark.ByteArrayComparer.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace Neo.Extensions | ||
{ | ||
public class Benchmark_ByteArrayComparer | ||
{ | ||
private ByteArrayComparer comparer = ByteArrayComparer.Default; | ||
private ByteArrayComparerV0 _oldComparer = ByteArrayComparerV0.Default; | ||
private byte[]? x, y; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
comparer = ByteArrayComparer.Default; | ||
_oldComparer = ByteArrayComparerV0.Default; | ||
} | ||
|
||
[GlobalSetup(Target = nameof(NewCompare_50Bytes))] | ||
public void SetupNew50Bytes() | ||
{ | ||
comparer = ByteArrayComparer.Default; | ||
|
||
x = new byte[50]; // 50 bytes | ||
y = new byte[50]; // 50 bytes | ||
Array.Fill(x, (byte)0xCC); | ||
Array.Copy(x, y, x.Length); | ||
} | ||
|
||
[Benchmark] | ||
public void NewCompare_50Bytes() | ||
{ | ||
comparer.Compare(x, y); | ||
} | ||
|
||
[GlobalSetup(Target = nameof(OldCompare_50Bytes))] | ||
public void SetupOld50Bytes() | ||
{ | ||
_oldComparer = ByteArrayComparerV0.Default; | ||
|
||
x = new byte[50]; // 50 bytes | ||
y = new byte[50]; // 50 bytes | ||
Array.Fill(x, (byte)0xCC); | ||
Array.Copy(x, y, x.Length); | ||
} | ||
|
||
[Benchmark] | ||
public void OldCompare_50Bytes() | ||
{ | ||
_oldComparer.Compare(x, y); | ||
} | ||
|
||
[GlobalSetup(Target = nameof(NewCompare_500Bytes))] | ||
public void SetupNew500Bytes() | ||
{ | ||
comparer = ByteArrayComparer.Default; | ||
|
||
x = new byte[500]; // 500 bytes | ||
y = new byte[500]; // 500 bytes | ||
Array.Fill(x, (byte)0xCC); | ||
Array.Copy(x, y, x.Length); | ||
} | ||
|
||
[Benchmark] | ||
public void NewCompare_500Bytes() | ||
{ | ||
comparer.Compare(x, y); | ||
} | ||
|
||
[GlobalSetup(Target = nameof(OldCompare_500Bytes))] | ||
public void SetupOld500Bytes() | ||
{ | ||
_oldComparer = ByteArrayComparerV0.Default; | ||
|
||
x = new byte[500]; // 500 bytes | ||
y = new byte[500]; // 500 bytes | ||
Array.Fill(x, (byte)0xCC); | ||
Array.Copy(x, y, x.Length); | ||
} | ||
|
||
[Benchmark] | ||
public void OldCompare_500Bytes() | ||
{ | ||
_oldComparer.Compare(x, y); | ||
} | ||
|
||
[GlobalSetup(Target = nameof(NewCompare_5000Bytes))] | ||
public void SetupNew5000Bytes() | ||
{ | ||
comparer = ByteArrayComparer.Default; | ||
|
||
x = new byte[5000]; // 5000 bytes | ||
y = new byte[5000]; // 5000 bytes | ||
Array.Fill(x, (byte)0xCC); | ||
Array.Copy(x, y, x.Length); | ||
} | ||
|
||
[Benchmark] | ||
public void NewCompare_5000Bytes() | ||
{ | ||
comparer.Compare(x, y); | ||
} | ||
|
||
[GlobalSetup(Target = nameof(OldCompare_5000Bytes))] | ||
public void SetupOld5000Bytes() | ||
{ | ||
_oldComparer = ByteArrayComparerV0.Default; | ||
|
||
x = new byte[5000]; // 5000 bytes | ||
y = new byte[5000]; // 5000 bytes | ||
Array.Fill(x, (byte)0xCC); | ||
Array.Copy(x, y, x.Length); | ||
} | ||
|
||
[Benchmark] | ||
public void OldCompare_5000Bytes() | ||
{ | ||
_oldComparer.Compare(x, y); | ||
} | ||
|
||
[GlobalSetup(Target = nameof(NewCompare_50000Bytes))] | ||
public void SetupNew50000Bytes() | ||
{ | ||
comparer = ByteArrayComparer.Default; | ||
|
||
x = new byte[50000]; // 50000 bytes | ||
y = new byte[50000]; // 50000 bytes | ||
Array.Fill(x, (byte)0xCC); | ||
Array.Copy(x, y, x.Length); | ||
} | ||
|
||
[Benchmark] | ||
public void NewCompare_50000Bytes() | ||
{ | ||
comparer.Compare(x, y); | ||
} | ||
|
||
[GlobalSetup(Target = nameof(OldCompare_50000Bytes))] | ||
public void SetupOld50000Bytes() | ||
{ | ||
_oldComparer = ByteArrayComparerV0.Default; | ||
|
||
x = new byte[50000]; // 50000 bytes | ||
y = new byte[50000]; // 50000 bytes | ||
Array.Fill(x, (byte)0xCC); | ||
Array.Copy(x, y, x.Length); | ||
} | ||
|
||
[Benchmark] | ||
public void OldCompare_50000Bytes() | ||
{ | ||
_oldComparer.Compare(x, y); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
benchmarks/Neo.Extensions.Benchmarks/Neo.Extensions.Benchmarks.csproj
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,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RootNamespace>Neo.Extensions</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" /> | ||
<ProjectReference Include="..\..\src\Neo.Extensions\Neo.Extensions.csproj" /> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,15 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// Program.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using BenchmarkDotNet.Running; | ||
using Neo.Extensions; | ||
|
||
BenchmarkRunner.Run(typeof(Benchmark_ByteArrayComparer)); |
Oops, something went wrong.