-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3475 from Horusiath/benchmark-dot-net
Introducing BenchmarkDotNet benchmarks
- Loading branch information
Showing
19 changed files
with
1,050 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/benchmark/Akka.Benchmarks/Actor/ActorPathBenchmarks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="ActorPathBenchmarks.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2009-2018 Lightbend Inc. <http://www.lightbend.com> | ||
// Copyright (C) 2013-2018 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using Akka.Actor; | ||
using Akka.Benchmarks.Configurations; | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace Akka.Benchmarks.Actor | ||
{ | ||
[Config(typeof(MicroBenchmarkConfig))] | ||
public class ActorPathBenchmarks | ||
{ | ||
private ActorPath x; | ||
private ActorPath y; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
x = new RootActorPath(new Address("akka.tcp", "system", "127.0.0.1", 1337), "user"); | ||
y = new RootActorPath(new Address("akka.tcp", "system", "127.0.0.1", 1337), "system"); | ||
} | ||
|
||
[Benchmark] | ||
public ActorPath ActorPath_Parse() | ||
{ | ||
return ActorPath.Parse("akka.tcp://system/user/parent/child"); | ||
} | ||
|
||
[Benchmark] | ||
public ActorPath ActorPath_Concat() | ||
{ | ||
return x / "parent" / "child"; | ||
} | ||
|
||
[Benchmark] | ||
public bool ActorPath_Equals() | ||
{ | ||
return x == y; | ||
} | ||
|
||
[Benchmark] | ||
public string ActorPath_ToString() | ||
{ | ||
return x.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="AddressBenchmarks.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2009-2018 Lightbend Inc. <http://www.lightbend.com> | ||
// Copyright (C) 2013-2018 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using Akka.Actor; | ||
using Akka.Benchmarks.Configurations; | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace Akka.Benchmarks.Actor | ||
{ | ||
[Config(typeof(MicroBenchmarkConfig))] | ||
public class AddressBenchmarks | ||
{ | ||
private Address x; | ||
private Address y; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
x = new Address("akka.tcp", "test-system", "10.62.0.101", 4000); | ||
y = new Address("akka.tcp", "test-system", "10.62.0.101", 4123); | ||
} | ||
|
||
[Benchmark] | ||
public Address Address_Parse() | ||
{ | ||
return Address.Parse("akka.tcp://test-system@10.62.0.100:5000/"); | ||
} | ||
|
||
[Benchmark] | ||
public int Address_CompareTo() | ||
{ | ||
return x.CompareTo(y); | ||
} | ||
|
||
[Benchmark] | ||
public string Address_ToString() | ||
{ | ||
return x.ToString(); | ||
} | ||
|
||
[Benchmark] | ||
public bool Address_Equals() | ||
{ | ||
return x == y; | ||
} | ||
|
||
[Benchmark] | ||
public int Address_GetHashCode() | ||
{ | ||
return x.GetHashCode(); | ||
} | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
src/benchmark/Akka.Benchmarks/Actor/PingPongBenchmarks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// //----------------------------------------------------------------------- | ||
// <copyright file="PingPongBenchmarks.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2009-2018 Lightbend Inc. <http://www.lightbend.com> | ||
// Copyright (C) 2013-2018 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Akka.Actor; | ||
using Akka.Benchmarks.Configurations; | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Attributes.Jobs; | ||
using BenchmarkDotNet.Engines; | ||
|
||
namespace Akka.Benchmarks.Actor | ||
{ | ||
[Config(typeof(MonitoringConfig))] | ||
[SimpleJob(RunStrategy.Monitoring, launchCount: 3, warmupCount: 3, targetCount: 3)] | ||
public class PingPongBenchmarks | ||
{ | ||
public const int Operations = 1_000_000; | ||
private TimeSpan timeout; | ||
private ActorSystem system; | ||
private IActorRef ping; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
timeout = TimeSpan.FromMinutes(1); | ||
system = ActorSystem.Create("system"); | ||
var pong = system.ActorOf(Props.Create(() => new Pong())); | ||
ping = system.ActorOf(Props.Create(() => new Ping(pong))); | ||
} | ||
|
||
[GlobalCleanup] | ||
public void Cleanup() | ||
{ | ||
system.Dispose(); | ||
} | ||
|
||
[Benchmark(OperationsPerInvoke = Operations)] | ||
public async Task Actor_ping_pong_single_pair_in_memory() | ||
{ | ||
await ping.Ask(StartTest.Instance, timeout); | ||
} | ||
|
||
#region actors | ||
|
||
sealed class StartTest | ||
{ | ||
public static readonly StartTest Instance = new StartTest(); | ||
private StartTest() { } | ||
} | ||
|
||
sealed class Signal | ||
{ | ||
public int Remaining { get; } | ||
|
||
public Signal(int remaining) | ||
{ | ||
Remaining = remaining; | ||
} | ||
} | ||
|
||
sealed class TestDone | ||
{ | ||
public static readonly TestDone Instance = new TestDone(); | ||
private TestDone() { } | ||
} | ||
|
||
sealed class Ping : ReceiveActor | ||
{ | ||
private IActorRef replyTo; | ||
|
||
public Ping(IActorRef pong) | ||
{ | ||
Receive<StartTest>(_ => | ||
{ | ||
replyTo = Sender; | ||
|
||
var signal = new Signal(Operations); | ||
pong.Tell(signal); | ||
}); | ||
|
||
Receive<Signal>(signal => | ||
{ | ||
var remaining = signal.Remaining; | ||
if (remaining <= 0) | ||
{ | ||
replyTo.Tell(TestDone.Instance); | ||
} | ||
else | ||
{ | ||
Sender.Tell(new Signal(remaining - 1)); | ||
} | ||
}); | ||
} | ||
} | ||
sealed class Pong : ReceiveActor | ||
{ | ||
public Pong() | ||
{ | ||
Receive<Signal>(signal => | ||
{ | ||
Sender.Tell(new Signal(signal.Remaining - 1)); | ||
}); | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
} | ||
} |
Oops, something went wrong.