Skip to content

Commit

Permalink
added req/s reporting for macro-benchmarks (#6829)
Browse files Browse the repository at this point in the history
* added req/s reporting for macro-benchmarks

* increase iteration counts

* fixed compilation error
  • Loading branch information
Aaronontheweb committed Jul 11, 2023
1 parent a66295b commit c72855b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/benchmark/Akka.Benchmarks/Actor/PingPongBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
namespace Akka.Benchmarks.Actor
{
[Config(typeof(MonitoringConfig))]
[SimpleJob(RunStrategy.Monitoring, launchCount: 3, warmupCount: 3, targetCount: 3)]
[SimpleJob(RunStrategy.Monitoring, launchCount: 10, warmupCount: 10, targetCount: 10)]
public class PingPongBenchmarks
{
public const int Operations = 1_000_000;
private TimeSpan timeout;
private ActorSystem system;
private IActorRef ping;

[GlobalSetup]
[IterationSetup]
public void Setup()
{
timeout = TimeSpan.FromMinutes(1);
Expand All @@ -33,13 +33,13 @@ public void Setup()
ping = system.ActorOf(Props.Create(() => new Ping(pong)));
}

[GlobalCleanup]
[IterationCleanup]
public void Cleanup()
{
system.Dispose();
}

[Benchmark(OperationsPerInvoke = Operations)]
[Benchmark(OperationsPerInvoke = Operations * 2)]
public async Task Actor_ping_pong_single_pair_in_memory()
{
await ping.Ask(StartTest.Instance, timeout);
Expand Down
42 changes: 39 additions & 3 deletions src/benchmark/Akka.Benchmarks/Configurations/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,57 @@
// </copyright>
//-----------------------------------------------------------------------

using System.Reflection;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;

namespace Akka.Benchmarks.Configurations
{
public class RequestsPerSecondColumn : IColumn
{
public string Id => nameof(RequestsPerSecondColumn);
public string ColumnName => "Req/sec";

public bool IsDefault(Summary summary, BenchmarkCase benchmarkCase) => false;
public string GetValue(Summary summary, BenchmarkCase benchmarkCase) => GetValue(summary, benchmarkCase, null);
public bool IsAvailable(Summary summary) => true;
public bool AlwaysShow => true;
public ColumnCategory Category => ColumnCategory.Custom;
public int PriorityInCategory => -1;
public bool IsNumeric => true;
public UnitType UnitType => UnitType.Dimensionless;
public string Legend => "Requests per Second";

public string GetValue(Summary summary, BenchmarkCase benchmarkCase, SummaryStyle style)
{
var benchmarkAttribute = benchmarkCase.Descriptor.WorkloadMethod.GetCustomAttribute<BenchmarkAttribute>();
var totalOperations = benchmarkAttribute?.OperationsPerInvoke ?? 1;

var report = summary[benchmarkCase];
var nsPerOperation = report.ResultStatistics.Mean;
var operationsPerSecond = 1 / (nsPerOperation / 1e9);


return operationsPerSecond.ToString("N2"); // or format as you like
}
}


/// <summary>
/// Basic BenchmarkDotNet configuration used for microbenchmarks.
/// </summary>
public class MicroBenchmarkConfig : ManualConfig
{
public MicroBenchmarkConfig()
{
this.Add(MemoryDiagnoser.Default);
this.Add(MarkdownExporter.GitHub);
AddDiagnoser(MemoryDiagnoser.Default);
AddExporter(MarkdownExporter.GitHub);
AddLogger(ConsoleLogger.Default);
}
}
Expand All @@ -32,7 +67,8 @@ public class MonitoringConfig : ManualConfig
{
public MonitoringConfig()
{
this.Add(MarkdownExporter.GitHub);
AddExporter(MarkdownExporter.GitHub);
AddColumn(new RequestsPerSecondColumn());
}
}
}

0 comments on commit c72855b

Please sign in to comment.