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

Commit a684fd4

Browse files
committed
add benchmarks
1 parent bc5448c commit a684fd4

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

src/Miningcore.Tests/Benchmarks/BenchmarkRunner.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using BenchmarkDotNet.Configs;
33
using BenchmarkDotNet.Loggers;
44
using BenchmarkDotNet.Running;
5+
using Miningcore.Tests.Benchmarks.Crypto;
56
using Miningcore.Tests.Benchmarks.Stratum;
67
using Xunit;
78
using Xunit.Abstractions;
@@ -18,7 +19,7 @@ public Benchmarks(ITestOutputHelper output)
1819
}
1920

2021
[Fact(Skip = "** Uncomment me to run benchmarks **")]
21-
public void Run_Benchmarks()
22+
public void Run_Stratum_Benchmarks()
2223
{
2324
var logger = new AccumulationLogger();
2425

@@ -31,4 +32,19 @@ public void Run_Benchmarks()
3132
// write benchmark summary
3233
output.WriteLine(logger.GetLog());
3334
}
35+
36+
[Fact]
37+
public void Run_Crypto_Benchmarks()
38+
{
39+
var logger = new AccumulationLogger();
40+
41+
var config = ManualConfig.Create(DefaultConfig.Instance)
42+
.AddLogger(logger)
43+
.WithOptions(ConfigOptions.DisableOptimizationsValidator);
44+
45+
BenchmarkRunner.Run<EthashBenchmarks>(config);
46+
47+
// write benchmark summary
48+
output.WriteLine(logger.GetLog());
49+
}
3450
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Miningcore.Extensions;
2+
using System.Globalization;
3+
using System.Threading.Tasks;
4+
using BenchmarkDotNet.Attributes;
5+
using Miningcore.Crypto.Hashing.Ethash.Ethash;
6+
using NLog;
7+
8+
namespace Miningcore.Tests.Benchmarks.Crypto;
9+
10+
11+
[MemoryDiagnoser]
12+
public class EthashBenchmarks : TestBase
13+
{
14+
private readonly byte[] testHash = "5fc898f16035bf5ac9c6d9077ae1e3d5fc1ecc3c9fd5bee8bb00e810fdacbaa0".HexToByteArray();
15+
private readonly ulong testNonce = ulong.Parse("50377003e5d830ca", NumberStyles.HexNumber, CultureInfo.InvariantCulture);
16+
private const int testHeight = 60000;
17+
18+
private ILogger logger;
19+
20+
private readonly EthashLight ethash = new EthashLight();
21+
22+
[GlobalSetup]
23+
public void Setup()
24+
{
25+
ModuleInitializer.Initialize();
26+
logger = new NullLogger(LogManager.LogFactory);
27+
28+
ethash.Setup(3, 0);
29+
}
30+
31+
32+
[Benchmark]
33+
public async Task Ethash_Compute()
34+
{
35+
var cache = await ethash.GetCacheAsync(logger, testHeight);
36+
cache.Compute(logger, testHash, testNonce, out var mixDigest, out var result);
37+
}
38+
}
39+

src/Miningcore.Tests/Miningcore.Tests.csproj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,21 @@
7070
</Target>
7171

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

7878
<Copy SourceFiles="@(Libs)" DestinationFolder="$(OutDir)" />
7979
</Target>
80+
<ItemGroup>
81+
<None Include="$(OutDir)\**\*">
82+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
83+
<Link>%(RecursiveDir)\%(Filename)%(Extension)</Link>
84+
<Visible>False</Visible>
85+
</None>
86+
</ItemGroup>
87+
8088
</Project>
89+
90+

0 commit comments

Comments
 (0)