diff --git a/Libplanet.Benchmarks/Protocol.cs b/Libplanet.Benchmarks/Protocol.cs new file mode 100644 index 00000000000..7f389447885 --- /dev/null +++ b/Libplanet.Benchmarks/Protocol.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using BenchmarkDotNet.Attributes; +using Libplanet.Crypto; +using Libplanet.Tests.Net.Protocols; + +namespace Libplanet.Benchmarks +{ + public class Protocol + { + private readonly Dictionary _swarms; + + public Protocol() + { + _swarms = new Dictionary(); + } + + [Benchmark] + public async Task BootstrapManyTestSwarms() + { + const int count = 100; + var seed = CreateTestSwarm(); + seed.Start(); + var swarms = new TestSwarm[count]; + for (var i = 0; i < count; i++) + { + swarms[i] = CreateTestSwarm(); + swarms[i].Start(); + } + + foreach (var swarm in swarms) + { + await swarm.BootstrapAsync(new[] { seed.AsPeer }); + } + } + + private TestSwarm CreateTestSwarm( + PrivateKey privateKey = null, + int? tableSize = null, + int? bucketSize = null, + TimeSpan? networkDelay = null) + { + return new TestSwarm( + _swarms, + privateKey ?? new PrivateKey(), + tableSize, + bucketSize, + networkDelay); + } + } +}