Skip to content

Commit 0b0f994

Browse files
committed
Test case specifically to demonstrate that performance can vary depending on if WithId is being used.
1 parent e147416 commit 0b0f994

File tree

4 files changed

+44
-29
lines changed

4 files changed

+44
-29
lines changed

DeBroglie.Benchmark/Benchmarks.cs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using BenchmarkDotNet.Attributes;
2+
using BenchmarkDotNet.Diagnosers;
23
using BenchmarkDotNet.Diagnostics.Windows.Configs;
4+
using BenchmarkDotNet.Order;
35
using DeBroglie.Constraints;
46
using DeBroglie.Models;
57
using DeBroglie.Rot;
@@ -10,6 +12,27 @@
1012
namespace DeBroglie.Benchmark
1113
{
1214
//[EtwProfiler] // Or use -p ETW on command line
15+
//[ClrJob, MonoJob, CoreJob, CoreRtJob]
16+
//[LegacyJitX86Job, LegacyJitX64Job, RyuJitX64Job]
17+
/*
18+
[HardwareCounters(
19+
HardwareCounter.Timer,
20+
HardwareCounter.TotalIssues,
21+
HardwareCounter.BranchInstructions,
22+
HardwareCounter.CacheMisses,
23+
HardwareCounter.BranchMispredictions
24+
//HardwareCounter.TotalCycles,
25+
//HardwareCounter.UnhaltedCoreCycles,
26+
//HardwareCounter.InstructionRetired,
27+
//HardwareCounter.UnhaltedReferenceCycles,
28+
//HardwareCounter.LlcReference,
29+
//HardwareCounter.LlcMisses,
30+
//HardwareCounter.BranchInstructionRetired,
31+
//HardwareCounter.BranchMispredictsRetired
32+
)]
33+
*/
34+
//[DisassemblyDiagnoser(printAsm: true, printSource: true)]
35+
[Orderer(SummaryOrderPolicy.Declared, MethodOrderPolicy.Declared)]
1336
public class Benchmarks
1437
{
1538
private TilePropagator propagator1;
@@ -23,11 +46,6 @@ public class Benchmarks
2346
public void Setup()
2447
{
2548
FreeSetup();
26-
ChessSetup();
27-
CastleSetup();
28-
EdgedPathSetup();
29-
PathSetup();
30-
CountSetup();
3149
}
3250

3351
private void Check(TilePropagator p)
@@ -61,7 +79,6 @@ public void Free()
6179
propagator1.Run();
6280
}
6381

64-
6582
public void ChessSetup()
6683
{
6784
var topology = new Topology(10, 10, 10, false);
@@ -83,7 +100,7 @@ public void ChessSetup()
83100
propagator2 = new TilePropagator(model, topology, new TilePropagatorOptions { });
84101
}
85102

86-
[Benchmark]
103+
//[Benchmark]
87104
public void Chess()
88105
{
89106
propagator2.Clear();
@@ -101,7 +118,7 @@ public void CastleSetup()
101118
}
102119

103120

104-
[Benchmark]
121+
//[Benchmark]
105122
public void Castle()
106123
{
107124
propagator3.Clear();
@@ -193,8 +210,6 @@ public void EdgedPath()
193210
Check(propagator4);
194211
}
195212

196-
197-
198213
public void PathSetup()
199214
{
200215

@@ -218,7 +233,7 @@ public void PathSetup()
218233
});
219234
}
220235

221-
[Benchmark]
236+
//[Benchmark]
222237
public void Path()
223238
{
224239
propagator5.Clear();
@@ -271,7 +286,7 @@ public void CountSetup()
271286
propagator6 = new TilePropagator(model, topology, options);
272287
}
273288

274-
[Benchmark]
289+
//[Benchmark]
275290
public void Count()
276291
{
277292
propagator6.Clear();

DeBroglie.Benchmark/DeBroglie.Benchmark.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp2.1</TargetFramework>
5+
<TargetFrameworks>netcoreapp2.1;net472</TargetFrameworks>
66
<DebugType>pdbonly</DebugType>
77
<DebugSymbols>true</DebugSymbols>
88
</PropertyGroup>

DeBroglie.Benchmark/Program.cs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using BenchmarkDotNet.Configs;
2+
using BenchmarkDotNet.Environments;
3+
using BenchmarkDotNet.Jobs;
24
using BenchmarkDotNet.Running;
35

46
namespace DeBroglie.Benchmark
@@ -7,21 +9,13 @@ public class Program
79
{
810
public static void Main(string[] args)
911
{
10-
/*
11-
for (var i = 0; i < 20; i++)
12-
{
13-
var benchmark = new Benchmarks();
14-
benchmark.Setup();
15-
benchmark.EdgedPath();
16-
System.Console.WriteLine(i);
17-
}
18-
*/
19-
var benchmark = new Benchmarks();
20-
benchmark.FreeSetup();
21-
benchmark.Free();
22-
23-
//BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
24-
//BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, new DebugInProcessConfig());
12+
BenchmarkRunner
13+
.Run<Benchmarks>(
14+
DefaultConfig.Instance
15+
.With(Job.Default.WithId("A"))
16+
.With(Job.Default)
17+
.With(Job.Default.WithId("Z"))
18+
);
2519
}
2620
}
2721
}

DeBroglie/TilePropagatorTileSet.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,22 @@ internal TilePropagatorTileSet(IEnumerable<Tile> tiles)
1717
{
1818
Tiles = tiles.ToArray();
1919
OffsetToPatterns = new Dictionary<int, ISet<int>>();
20+
OffsetToPatternsBitArray = new Foo();
2021
}
2122

2223
public IReadOnlyCollection<Tile> Tiles { get; }
2324

2425
internal Dictionary<int, ISet<int>> OffsetToPatterns { get; }
25-
internal Dictionary<int, BitArray> OffsetToPatternsBitArray { get; }
26+
internal Foo OffsetToPatternsBitArray { get; }
2627

2728
public override string ToString()
2829
{
2930
return string.Join(",", Tiles);
3031
}
3132
}
33+
34+
class Foo
35+
{
36+
37+
}
3238
}

0 commit comments

Comments
 (0)