Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
add benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
jon4hz committed Mar 1, 2023
1 parent bc5448c commit a684fd4
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/Miningcore.Tests/Benchmarks/BenchmarkRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Running;
using Miningcore.Tests.Benchmarks.Crypto;
using Miningcore.Tests.Benchmarks.Stratum;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -18,7 +19,7 @@ public Benchmarks(ITestOutputHelper output)
}

[Fact(Skip = "** Uncomment me to run benchmarks **")]
public void Run_Benchmarks()
public void Run_Stratum_Benchmarks()
{
var logger = new AccumulationLogger();

Expand All @@ -31,4 +32,19 @@ public void Run_Benchmarks()
// write benchmark summary
output.WriteLine(logger.GetLog());
}

[Fact]
public void Run_Crypto_Benchmarks()
{
var logger = new AccumulationLogger();

var config = ManualConfig.Create(DefaultConfig.Instance)
.AddLogger(logger)
.WithOptions(ConfigOptions.DisableOptimizationsValidator);

BenchmarkRunner.Run<EthashBenchmarks>(config);

// write benchmark summary
output.WriteLine(logger.GetLog());
}
}
39 changes: 39 additions & 0 deletions src/Miningcore.Tests/Benchmarks/Crypto/EthashBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Miningcore.Extensions;
using System.Globalization;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using Miningcore.Crypto.Hashing.Ethash.Ethash;
using NLog;

namespace Miningcore.Tests.Benchmarks.Crypto;


[MemoryDiagnoser]
public class EthashBenchmarks : TestBase
{
private readonly byte[] testHash = "5fc898f16035bf5ac9c6d9077ae1e3d5fc1ecc3c9fd5bee8bb00e810fdacbaa0".HexToByteArray();
private readonly ulong testNonce = ulong.Parse("50377003e5d830ca", NumberStyles.HexNumber, CultureInfo.InvariantCulture);
private const int testHeight = 60000;

private ILogger logger;

private readonly EthashLight ethash = new EthashLight();

[GlobalSetup]
public void Setup()
{
ModuleInitializer.Initialize();
logger = new NullLogger(LogManager.LogFactory);

ethash.Setup(3, 0);
}


[Benchmark]
public async Task Ethash_Compute()
{
var cache = await ethash.GetCacheAsync(logger, testHeight);
cache.Compute(logger, testHash, testNonce, out var mixDigest, out var result);
}
}

12 changes: 11 additions & 1 deletion src/Miningcore.Tests/Miningcore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,21 @@
</Target>

<!-- Copy library binaries from Miningcore build output on Linux -->
<Target Name="CopyLibsLinux" AfterTargets="AfterBuild" Condition="'$(IsLinux)' == 'true'">
<Target Name="CopyLibsLinux" Condition="'$(IsLinux)' == 'true'">
<ItemGroup>
<Libs Include="$(ProjectDir)..\Miningcore\bin\$(Configuration)\net6.0\lib*.so" />
</ItemGroup>

<Copy SourceFiles="@(Libs)" DestinationFolder="$(OutDir)" />
</Target>
<ItemGroup>
<None Include="$(OutDir)\**\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>%(RecursiveDir)\%(Filename)%(Extension)</Link>
<Visible>False</Visible>
</None>
</ItemGroup>

</Project>


0 comments on commit a684fd4

Please sign in to comment.