Skip to content

Commit

Permalink
Use oakton to issue different commands for benchmark project (relates…
Browse files Browse the repository at this point in the history
… to #9)
  • Loading branch information
solyutor committed May 8, 2020
1 parent ba8fc6e commit 7977064
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Benchmark/Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
<PackageReference Include="Oakton" Version="2.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 14 additions & 0 deletions src/Benchmark/Commands/BenchCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using BenchmarkDotNet.Running;
using Oakton;

namespace Benchmark.Commands
{
public class BenchCommand : OaktonCommand<BenchInput>
{
public override bool Execute(BenchInput input)
{
BenchmarkRunner.Run<PingPongBenchmark>();
return true;
}
}
}
6 changes: 6 additions & 0 deletions src/Benchmark/Commands/BenchInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Benchmark.Commands
{
public class BenchInput
{
}
}
31 changes: 31 additions & 0 deletions src/Benchmark/Commands/ProfileCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using Oakton;

namespace Benchmark.Commands
{
public class ProfileCommand : OaktonCommand<ProfileInput>
{
public override bool Execute(ProfileInput input)
{
var benchmark = new PingPongBenchmark();
try
{
Console.WriteLine("Starting setup");
benchmark.GlobalSetup();
benchmark.IterationSetup();

Console.WriteLine("Starting profiling");
benchmark.Run_ping_pong_benchmark();

Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
finally
{
benchmark.GlobalCleanup();
}

return true;
}
}
}
7 changes: 7 additions & 0 deletions src/Benchmark/Commands/ProfileInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Benchmark.Commands
{
public class ProfileInput
{

}
}
14 changes: 13 additions & 1 deletion src/Benchmark/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
using System.Reflection;
using BenchmarkDotNet.Running;
using Oakton;

namespace Benchmark
{
internal class Program
{
private static void Main() => BenchmarkRunner.Run<PingPongBenchmark>();
private static int Main(string[] args)
{
var executor = CommandExecutor.For(_ =>
{
// Find and apply all command classes discovered
// in this assembly
_.RegisterCommands(typeof(Program).GetTypeInfo().Assembly);
});

return executor.Execute(args);
}
}
}

0 comments on commit 7977064

Please sign in to comment.