Skip to content
Permalink
Browse files

Add Libplanet.Benchmarks

[changelog skip]
  • Loading branch information...
earlbread committed Jul 26, 2019
1 parent fcb8d5c commit b89705f6242cb3c97c20244e9a237cb9b70dc0c7
@@ -30,6 +30,7 @@ _UpgradeReport_Files/
[Pp]ackages/
mono_crash.*.json
FodyWeavers.xsd
BenchmarkDotNet.Artifacts

Thumbs.db
Desktop.ini
@@ -0,0 +1,40 @@
<Project
xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RootNamespace>Libplanet.Benchmarks</RootNamespace>
<IsPackable>false</IsPackable>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<LangVersion>7.1</LangVersion>
<CodeAnalysisRuleSet>..\Libplanet.Tests.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="..\Menees.Analyzers.Settings.xml">
<Link>Menees.Analyzers.Settings.xml</Link>
</AdditionalFiles>
<AdditionalFiles Include="..\stylecop.json" />
</ItemGroup>

<PropertyGroup Condition=" '$(MSBuildRuntimeType)'=='Mono' And
'$(BuildingByReSharper)'!='true'">
<TargetFramework>net461</TargetFramework>
</PropertyGroup>

<PropertyGroup>
<CodeAnalysisRuleSet>..\Libplanet.Tests.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Libplanet\Libplanet.csproj" />
<ProjectReference Include="..\Libplanet.Tests\Libplanet.Tests.csproj" />
</ItemGroup>

</Project>
@@ -0,0 +1,103 @@
using BenchmarkDotNet.Attributes;
using Libplanet.Blockchain;
using Libplanet.Blocks;
using Libplanet.Crypto;
using Libplanet.Tests.Blockchain;
using Libplanet.Tests.Common.Action;
using Libplanet.Tests.Store;

namespace Libplanet.Benchmarks
{
public class MineBlock
{
private FileStoreFixture _fx;
private BlockChain<DumbAction> _blockChain;

public MineBlock()
{
_fx = new FileStoreFixture();
_blockChain = new BlockChain<DumbAction>(
new NullPolicy<DumbAction>(),
_fx.Store
);
}

[Benchmark]
public Block<DumbAction> MineBlockEmpty()
{
return _blockChain.MineBlock(_fx.Address1);
}

[IterationSetup(Target = "MineBlockOneTransactionNoAction")]
public void MakeOneTransactionNoAction()
{
_blockChain.MakeTransaction(new PrivateKey(), new DumbAction[] { });
}

[Benchmark]
public Block<DumbAction> MineBlockOneTransactionNoAction()
{
return _blockChain.MineBlock(_fx.Address1);
}

[IterationSetup(Target = "MineBlockTenTransactionsNoAction")]
public void MakeTenTransactionsNoAction()
{
for (var i = 0; i < 10; i++)
{
_blockChain.MakeTransaction(new PrivateKey(), new DumbAction[] { });
}
}

[Benchmark]
public Block<DumbAction> MineBlockTenTransactionsNoAction()
{
return _blockChain.MineBlock(_fx.Address1);
}

[IterationSetup(Target = "MineBlockOneTransactionWithActions")]
public void MakeOneTransactionWithActions()
{
var privateKey = new PrivateKey();
var address = privateKey.PublicKey.ToAddress();
var actions = new[]
{
new DumbAction(address, "foo"),
new DumbAction(address, "bar"),
new DumbAction(address, "baz"),
new DumbAction(address, "qux"),
};
_blockChain.MakeTransaction(privateKey, actions);
}

[Benchmark]
public Block<DumbAction> MineBlockOneTransactionWithActions()
{
return _blockChain.MineBlock(_fx.Address1);
}

[IterationSetup(Target = "MineBlockTenTransactionsWithActions")]
public void MakeTenTransactionsWithActions()
{
for (var i = 0; i < 10; i++)
{
var privateKey = new PrivateKey();
var address = privateKey.PublicKey.ToAddress();
var actions = new[]
{
new DumbAction(address, "foo"),
new DumbAction(address, "bar"),
new DumbAction(address, "baz"),
new DumbAction(address, "qux"),
};
_blockChain.MakeTransaction(privateKey, actions);
}
}

[Benchmark]
public Block<DumbAction> MineBlockTenTransactionsWithActions()
{
return _blockChain.MineBlock(_fx.Address1);
}
}
}
@@ -0,0 +1,10 @@
using BenchmarkDotNet.Running;

namespace Libplanet.Benchmarks
{
public class Program
{
public static void Main(string[] args)
=> BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
}
}
@@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet", "Libplanet\Libp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Tests", "Libplanet.Tests\Libplanet.Tests.csproj", "{3BA7D9BE-EBBF-432E-9880-0E2D2C17FCF8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libplanet.Benchmarks", "Libplanet.Benchmarks\Libplanet.Benchmarks.csproj", "{E010FB5E-0D68-4AF7-B632-5DB6B902F158}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -69,6 +71,18 @@ Global
{5C2B23E2-C286-412D-ADE1-F6796B7083DE}.Release|x64.Build.0 = Release|Any CPU
{5C2B23E2-C286-412D-ADE1-F6796B7083DE}.Release|x86.ActiveCfg = Release|Any CPU
{5C2B23E2-C286-412D-ADE1-F6796B7083DE}.Release|x86.Build.0 = Release|Any CPU
{E010FB5E-0D68-4AF7-B632-5DB6B902F158}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E010FB5E-0D68-4AF7-B632-5DB6B902F158}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E010FB5E-0D68-4AF7-B632-5DB6B902F158}.Debug|x64.ActiveCfg = Debug|Any CPU
{E010FB5E-0D68-4AF7-B632-5DB6B902F158}.Debug|x64.Build.0 = Debug|Any CPU
{E010FB5E-0D68-4AF7-B632-5DB6B902F158}.Debug|x86.ActiveCfg = Debug|Any CPU
{E010FB5E-0D68-4AF7-B632-5DB6B902F158}.Debug|x86.Build.0 = Debug|Any CPU
{E010FB5E-0D68-4AF7-B632-5DB6B902F158}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E010FB5E-0D68-4AF7-B632-5DB6B902F158}.Release|Any CPU.Build.0 = Release|Any CPU
{E010FB5E-0D68-4AF7-B632-5DB6B902F158}.Release|x64.ActiveCfg = Release|Any CPU
{E010FB5E-0D68-4AF7-B632-5DB6B902F158}.Release|x64.Build.0 = Release|Any CPU
{E010FB5E-0D68-4AF7-B632-5DB6B902F158}.Release|x86.ActiveCfg = Release|Any CPU
{E010FB5E-0D68-4AF7-B632-5DB6B902F158}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -170,3 +170,24 @@ jobs:
- template: .azure-pipelines/windows-net461.yml
parameters:
configuration: $(configuration)

- job: Windows_NETCore_Benchmark
pool:
vmImage: windows-2019
steps:
- task: UseDotNet@2
displayName: Install .NET Core SDK
inputs:
packageType: sdk
version: 2.2.203
installationPath: $(Agent.ToolsDirectory)/dotnet
- task: CmdLine@2
displayName: dotnet --version
inputs:
script: dotnet --version
- task: CmdLine@2
displayName: Benchmarks
inputs:
script: |
pushd Libplanet.Benchmarks
dotnet run -c Release -- -f *

0 comments on commit b89705f

Please sign in to comment.
You can’t perform that action at this time.