Skip to content

Commit 55a6126

Browse files
authored
Add Benchmarks project (#101)
1 parent fc4c801 commit 55a6126

File tree

7 files changed

+118
-1
lines changed

7 files changed

+118
-1
lines changed

Microsoft.DurableTask.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "src\Shared\Shared
5757
EndProject
5858
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "misc", "misc\misc.csproj", "{1E135970-60CF-470A-9270-4560BFA0A7DF}"
5959
EndProject
60+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmarks", "test\Benchmarks\Benchmarks.csproj", "{82C0CD7D-2764-421A-8256-7E2304D5A6E7}"
61+
EndProject
6062
Global
6163
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6264
Debug|Any CPU = Debug|Any CPU
@@ -143,6 +145,10 @@ Global
143145
{1E135970-60CF-470A-9270-4560BFA0A7DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
144146
{1E135970-60CF-470A-9270-4560BFA0A7DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
145147
{1E135970-60CF-470A-9270-4560BFA0A7DF}.Release|Any CPU.Build.0 = Release|Any CPU
148+
{82C0CD7D-2764-421A-8256-7E2304D5A6E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
149+
{82C0CD7D-2764-421A-8256-7E2304D5A6E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
150+
{82C0CD7D-2764-421A-8256-7E2304D5A6E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
151+
{82C0CD7D-2764-421A-8256-7E2304D5A6E7}.Release|Any CPU.Build.0 = Release|Any CPU
146152
EndGlobalSection
147153
GlobalSection(SolutionProperties) = preSolution
148154
HideSolutionNode = FALSE
@@ -171,6 +177,7 @@ Global
171177
{8A0156E6-F033-49AB-AB0C-6698CE1DB24F} = {EFF7632B-821E-4CFC-B4A0-ED4B24296B17}
172178
{21AF0D71-6D32-483F-B6E8-3B28EE432560} = {EFF7632B-821E-4CFC-B4A0-ED4B24296B17}
173179
{57A4C812-B0D9-49E9-9EBE-7E94D3D78ED7} = {8AFC9781-F6F1-4696-BB4A-9ED7CA9D612B}
180+
{82C0CD7D-2764-421A-8256-7E2304D5A6E7} = {E5637F81-2FB9-4CD7-900D-455363B142A7}
174181
EndGlobalSection
175182
GlobalSection(ExtensibilityGlobals) = postSolution
176183
SolutionGuid = {AB41CB55-35EA-4986-A522-387AB3402E71}

src/Abstractions/DurableTaskRegistry.Activities.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ TaskName ITaskActivity singleton
3939
/// <returns>The same registry, for call chaining.</returns>
4040
public DurableTaskRegistry AddActivity(TaskName name, Type type)
4141
{
42-
// TODO: Compile a constructor expression for performance -- ActivatorUtilities.CreateFactory
4342
Check.ConcreteType<ITaskActivity>(type);
4443
return this.AddActivity(name, sp => (ITaskActivity)ActivatorUtilities.GetServiceOrCreateInstance(sp, type));
4544
}

src/Directory.Build.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
<ItemGroup>
2525
<InternalsVisibleTo Include="$(AssemblyName).Tests" Key="$(StrongNamePublicKey)" />
26+
<InternalsVisibleTo Include="Benchmarks" Key="$(StrongNamePublicKey)" />
2627
</ItemGroup>
2728

2829
<Import Project="$(EngRoot)targets/SharedFiles.targets" />

test/Benchmarks/Benchmarks.csproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<AssemblyName>Benchmarks</AssemblyName>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="BenchmarkDotNet" Version="0.13.2" />
10+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="$(SrcRoot)Worker/Core/Worker.csproj" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<!-- Make sure these properties come early -->
5+
<PlatformTarget>AnyCPU</PlatformTarget>
6+
<DebugType>pdbonly</DebugType>
7+
<DebugSymbols>true</DebugSymbols>
8+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
9+
<Optimize>true</Optimize>
10+
<Configuration>Release</Configuration>
11+
</PropertyGroup>
12+
13+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)../, $(_DirectoryBuildPropsFile)))/$(_DirectoryBuildPropsFile)"
14+
Condition=" '$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)../, $(_DirectoryBuildPropsFile)))' != '' " />
15+
16+
</Project>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using BenchmarkDotNet.Attributes;
5+
using Microsoft.DurableTask.Worker;
6+
using Microsoft.Extensions.DependencyInjection;
7+
8+
namespace Microsoft.DurableTask.Benchmarks;
9+
10+
[MemoryDiagnoser]
11+
public class DurableTaskRegistryBenchmarks
12+
{
13+
readonly IServiceProvider services;
14+
15+
public DurableTaskRegistryBenchmarks()
16+
{
17+
ServiceCollection services = new();
18+
services.AddTransient<FromServicesActivity>();
19+
this.services = services.BuildServiceProvider();
20+
}
21+
22+
[Benchmark]
23+
public void CreateActivity_FromServices()
24+
{
25+
DurableTaskRegistry registry = new();
26+
TaskName name = nameof(FromServicesActivity);
27+
registry.AddActivity<FromServicesActivity>(name);
28+
IDurableTaskFactory factory = registry.BuildFactory();
29+
30+
for (int i = 0; i < 100; i++)
31+
{
32+
factory.TryCreateActivity(name, this.services, out _);
33+
}
34+
}
35+
36+
[Benchmark]
37+
public void CreateActivity_FromActivator()
38+
{
39+
DurableTaskRegistry registry = new();
40+
TaskName name = nameof(FromActivatorActivity);
41+
registry.AddActivity<FromActivatorActivity>(name);
42+
IDurableTaskFactory factory = registry.BuildFactory();
43+
44+
for (int i = 0; i < 100; i++)
45+
{
46+
factory.TryCreateActivity(name, this.services, out _);
47+
}
48+
}
49+
50+
class FromServicesActivity : TaskActivity<string, string>
51+
{
52+
public override Task<string> RunAsync(TaskActivityContext context, string input)
53+
{
54+
throw new NotImplementedException();
55+
}
56+
}
57+
58+
class FromActivatorActivity : TaskActivity<string, string>
59+
{
60+
public override Task<string> RunAsync(TaskActivityContext context, string input)
61+
{
62+
throw new NotImplementedException();
63+
}
64+
}
65+
}

test/Benchmarks/Program.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using BenchmarkDotNet.Running;
5+
using Microsoft.DurableTask;
6+
7+
BenchmarkSwitcher.FromAssembly(typeof(AssemblyMarker).Assembly).Run(args);
8+
9+
namespace Microsoft.DurableTask
10+
{
11+
class AssemblyMarker { }
12+
}

0 commit comments

Comments
 (0)