Skip to content

Commit e3ab4d1

Browse files
Add BenchmarkDotNet benchmark project and DataLoader benchmark (#159)
Co-authored-by: Matt Johnson-Pint <mattjohnsonpint@gmail.com>
1 parent 601a31d commit e3ab4d1

File tree

6 files changed

+76
-0
lines changed

6 files changed

+76
-0
lines changed

TimeZoneConverter.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TimeZoneConverter.Posix", "
2424
EndProject
2525
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TimeZoneConverter.Posix.Tests", "test\TimeZoneConverter.Posix.Tests\TimeZoneConverter.Posix.Tests.csproj", "{3EF2A004-2823-4C13-AB04-8A7B415B49C7}"
2626
EndProject
27+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TimeZoneConverter.Benchmarks", "test\TimeZoneConverter.Benchmarks\TimeZoneConverter.Benchmarks.csproj", "{66C9F893-5C13-4B14-B870-594459EB739F}"
28+
EndProject
2729
Global
2830
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2931
Debug|Any CPU = Debug|Any CPU
@@ -50,6 +52,10 @@ Global
5052
{3EF2A004-2823-4C13-AB04-8A7B415B49C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
5153
{3EF2A004-2823-4C13-AB04-8A7B415B49C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
5254
{3EF2A004-2823-4C13-AB04-8A7B415B49C7}.Release|Any CPU.Build.0 = Release|Any CPU
55+
{66C9F893-5C13-4B14-B870-594459EB739F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
56+
{66C9F893-5C13-4B14-B870-594459EB739F}.Debug|Any CPU.Build.0 = Debug|Any CPU
57+
{66C9F893-5C13-4B14-B870-594459EB739F}.Release|Any CPU.ActiveCfg = Release|Any CPU
58+
{66C9F893-5C13-4B14-B870-594459EB739F}.Release|Any CPU.Build.0 = Release|Any CPU
5359
EndGlobalSection
5460
GlobalSection(SolutionProperties) = preSolution
5561
HideSolutionNode = FALSE
@@ -60,6 +66,7 @@ Global
6066
{902AFB31-8432-4C34-89AB-2CFF4DD27B93} = {62E4880C-D978-413C-AB12-E74B2E47426E}
6167
{6E9924D5-04AA-4063-AD77-02C68112D612} = {9C922A24-67F8-4E45-B079-130DDAC3B5A7}
6268
{3EF2A004-2823-4C13-AB04-8A7B415B49C7} = {62E4880C-D978-413C-AB12-E74B2E47426E}
69+
{66C9F893-5C13-4B14-B870-594459EB739F} = {62E4880C-D978-413C-AB12-E74B2E47426E}
6370
EndGlobalSection
6471
GlobalSection(ExtensibilityGlobals) = postSolution
6572
SolutionGuid = {404E04B4-C30C-452D-8705-DDF6C17AE7D0}

src/TimeZoneConverter/TimeZoneConverter.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@
2121
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
2222
</ItemGroup>
2323

24+
<ItemGroup>
25+
<InternalsVisibleTo Include="TimeZoneConverter.Benchmarks, PublicKey=0024000004800000940000000602000000240000525341310004000001000100B1DAE8576C79F6AA981231315A688EBF26AE1ACD5BF2806C272C21B59DBA8A9F6432D4D00E56B3E474A4574BB730126B76A3B8DD4F97EA020DF7718F8090BC12CBB24A08DC8CA987B91FD24CE1C24E85E930FD01268405EC64FE08AB52A7DE9F1806E1F3C5886422D73780F5A69FF7015701F3D2C31094AF1065EF722A86179A" />
26+
</ItemGroup>
27+
2428
</Project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using BenchmarkDotNet.Attributes;
2+
3+
namespace TimeZoneConverter.Benchmarks;
4+
5+
[MemoryDiagnoser]
6+
public class DataLoaderBenchmark
7+
{
8+
private static readonly Dictionary<string, string> IanaMap = new();
9+
private static readonly Dictionary<string, string> WindowsMap = new();
10+
private static readonly Dictionary<string, string> RailsMap = new();
11+
private static readonly Dictionary<string, IList<string>> InverseRailsMap = new();
12+
private static readonly Dictionary<string, string> Links = new();
13+
private static readonly Dictionary<string, IList<string>> IanaTerritoryZones = new();
14+
15+
[IterationSetup]
16+
public void IterationSetup()
17+
{
18+
IanaMap.Clear();
19+
WindowsMap.Clear();
20+
RailsMap.Clear();
21+
InverseRailsMap.Clear();
22+
Links.Clear();
23+
IanaTerritoryZones.Clear();
24+
}
25+
26+
[Benchmark]
27+
public void Load()
28+
{
29+
DataLoader.Populate(IanaMap, WindowsMap, RailsMap, InverseRailsMap, Links, IanaTerritoryZones);
30+
}
31+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project>
2+
3+
<Import Project="..\..\Directory.Build.props" />
4+
5+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using BenchmarkDotNet.Running;
2+
3+
namespace TimeZoneConverter.Benchmarks;
4+
5+
public static class Program
6+
{
7+
public static void Main(string[]? args)
8+
{
9+
BenchmarkSwitcher.FromAssembly(typeof(DataLoaderBenchmark).Assembly).Run(args);
10+
}
11+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net8.0</TargetFrameworks>
5+
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)..\..\.assets\mattjohnsonpint.snk</AssemblyOriginatorKeyFile>
6+
<SignAssembly>true</SignAssembly>
7+
<OutputType>exe</OutputType>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\..\src\TimeZoneConverter\TimeZoneConverter.csproj" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
16+
</ItemGroup>
17+
18+
</Project>

0 commit comments

Comments
 (0)