-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
269 additions
and
7 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
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> | ||
</packageSources> | ||
</configuration> |
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
14 changes: 14 additions & 0 deletions
14
...enchmarkDotNet.Artifacts/results/MediatR.Benchmarks.Benchmarks-report-github.md
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,14 @@ | ||
``` ini | ||
|
||
BenchmarkDotNet=v0.11.5, OS=Windows 10.0.18363 | ||
Intel Core i7-7700HQ CPU 2.80GHz (Kaby Lake), 1 CPU, 8 logical and 4 physical cores | ||
.NET Core SDK=3.1.100 | ||
[Host] : .NET Core 3.0.0 (CoreCLR 4.700.19.46205, CoreFX 4.700.19.46214), 64bit RyuJIT | ||
DefaultJob : .NET Core 3.0.0 (CoreCLR 4.700.19.46205, CoreFX 4.700.19.46214), 64bit RyuJIT | ||
|
||
|
||
``` | ||
| Method | Mean | Error | StdDev | | ||
|------------------------ |----------:|----------:|----------:| | ||
| SendingRequests | 23.748 us | 0.8423 us | 2.2915 us | | ||
| PublishingNotifications | 9.289 us | 0.2322 us | 0.6587 us | |
3 changes: 3 additions & 0 deletions
3
...atR.Benchmarks/BenchmarkDotNet.Artifacts/results/MediatR.Benchmarks.Benchmarks-report.csv
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,3 @@ | ||
Method,Job,AnalyzeLaunchVariance,EvaluateOverhead,MaxAbsoluteError,MaxRelativeError,MinInvokeCount,MinIterationTime,OutlierMode,Affinity,EnvironmentVariables,Jit,Platform,Runtime,AllowVeryLargeObjects,Concurrent,CpuGroups,Force,HeapAffinitizeMask,HeapCount,NoAffinitize,RetainVm,Server,PowerPlan,Arguments,BuildConfiguration,Clock,EngineFactory,NuGetReferences,Toolchain,IsMutator,InvocationCount,IterationCount,IterationTime,LaunchCount,MaxIterationCount,MaxWarmupIterationCount,MinIterationCount,MinWarmupIterationCount,RunStrategy,UnrollFactor,WarmupCount,Mean,Error,StdDev | ||
SendingRequests,Default,False,Default,Default,Default,Default,Default,Default,11111111,Empty,RyuJit,X64,Core,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,1,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,23.748 us,0.8423 us,2.2915 us | ||
PublishingNotifications,Default,False,Default,Default,Default,Default,Default,Default,11111111,Empty,RyuJit,X64,Core,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,1,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,9.289 us,0.2322 us,0.6587 us |
31 changes: 31 additions & 0 deletions
31
...tR.Benchmarks/BenchmarkDotNet.Artifacts/results/MediatR.Benchmarks.Benchmarks-report.html
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,31 @@ | ||
<!DOCTYPE html> | ||
<html lang='en'> | ||
<head> | ||
<meta charset='utf-8' /> | ||
<title>MediatR.Benchmarks.Benchmarks-20200102-124854</title> | ||
|
||
<style type="text/css"> | ||
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; } | ||
td, th { padding: 6px 13px; border: 1px solid #ddd; } | ||
tr { background-color: #fff; border-top: 1px solid #ccc; } | ||
tr:nth-child(even) { background: #f8f8f8; } | ||
</style> | ||
</head> | ||
<body> | ||
<pre><code> | ||
BenchmarkDotNet=v0.11.5, OS=Windows 10.0.18363 | ||
Intel Core i7-7700HQ CPU 2.80GHz (Kaby Lake), 1 CPU, 8 logical and 4 physical cores | ||
.NET Core SDK=3.1.100 | ||
[Host] : .NET Core 3.0.0 (CoreCLR 4.700.19.46205, CoreFX 4.700.19.46214), 64bit RyuJIT | ||
DefaultJob : .NET Core 3.0.0 (CoreCLR 4.700.19.46205, CoreFX 4.700.19.46214), 64bit RyuJIT | ||
</code></pre> | ||
<pre><code></code></pre> | ||
|
||
<table> | ||
<thead><tr><th> Method</th><th>Mean</th><th>Error</th><th>StdDev</th> | ||
</tr> | ||
</thead><tbody><tr><td>SendingRequests</td><td>23.748 us</td><td>0.8423 us</td><td>2.2915 us</td> | ||
</tr><tr><td>PublishingNotifications</td><td>9.289 us</td><td>0.2322 us</td><td>0.6587 us</td> | ||
</tr></tbody></table> | ||
</body> | ||
</html> |
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,50 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using BenchmarkDotNet; | ||
using BenchmarkDotNet.Attributes; | ||
using MediatR.Examples; | ||
using MediatR.Pipeline; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace MediatR.Benchmarks | ||
{ | ||
[DotTraceDiagnoser] | ||
public class Benchmarks | ||
{ | ||
private IMediator _mediator; | ||
private readonly Ping _request = new Ping {Message = "Hello World"}; | ||
private readonly Pinged _notification = new Pinged(); | ||
|
||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
var services = new ServiceCollection(); | ||
|
||
services.AddSingleton(TextWriter.Null); | ||
|
||
services.AddMediatR(typeof(Ping)); | ||
|
||
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(GenericPipelineBehavior<,>)); | ||
services.AddScoped(typeof(IRequestPreProcessor<>), typeof(GenericRequestPreProcessor<>)); | ||
services.AddScoped(typeof(IRequestPostProcessor<,>), typeof(GenericRequestPostProcessor<,>)); | ||
|
||
var provider = services.BuildServiceProvider(); | ||
|
||
_mediator = provider.GetRequiredService<IMediator>(); | ||
} | ||
|
||
[Benchmark] | ||
public Task SendingRequests() | ||
{ | ||
return _mediator.Send(_request); | ||
} | ||
|
||
[Benchmark] | ||
public Task PublishingNotifications() | ||
{ | ||
return _mediator.Publish(_notification); | ||
} | ||
} | ||
} |
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,119 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using BenchmarkDotNet.Analysers; | ||
using BenchmarkDotNet.Configs; | ||
using BenchmarkDotNet.Diagnosers; | ||
using BenchmarkDotNet.Diagnostics.Windows; | ||
using BenchmarkDotNet.Engines; | ||
using BenchmarkDotNet.Exporters; | ||
using BenchmarkDotNet.Loggers; | ||
using BenchmarkDotNet.Reports; | ||
using BenchmarkDotNet.Running; | ||
using BenchmarkDotNet.Validators; | ||
|
||
namespace MediatR.Benchmarks | ||
{ | ||
internal sealed class DotTraceDiagnoserAttribute : Attribute, IConfigSource | ||
{ | ||
public DotTraceDiagnoserAttribute() | ||
{ | ||
var manualConfig = ManualConfig.CreateEmpty(); | ||
manualConfig.Add(new DotTraceDiagnoser()); | ||
Config = manualConfig; | ||
} | ||
|
||
public IConfig Config { get; } | ||
} | ||
|
||
internal sealed class DotTraceDiagnoser : IDiagnoser | ||
{ | ||
private Process _process; | ||
private string _saveLocation; | ||
|
||
public DotTraceDiagnoser() | ||
{ | ||
_saveLocation = $"C:\\temp\\MyProject\\{DateTimeOffset.Now.UtcDateTime:yyyyMMddTHHmmss}.bench.dtp"; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public RunMode GetRunMode(BenchmarkCase benchmarkCase) => RunMode.ExtraRun; | ||
|
||
/// <inheritdoc /> | ||
public void Handle(HostSignal signal, DiagnoserActionParameters parameters) | ||
{ | ||
switch (signal) | ||
{ | ||
case HostSignal.BeforeActualRun: | ||
try | ||
{ | ||
var dotTracePath = Path.Combine( | ||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), | ||
@"JetBrains\Installations\dotTrace192\ConsoleProfiler.exe"); | ||
var startInfo = new ProcessStartInfo( | ||
dotTracePath, | ||
$"attach {parameters.Process.Id} --save-to={_saveLocation} --profiling-type=Sampling") | ||
{ | ||
RedirectStandardError | ||
= true, | ||
RedirectStandardOutput = true, | ||
WindowStyle = ProcessWindowStyle.Normal, | ||
UseShellExecute = false, | ||
}; | ||
Console.WriteLine(startInfo.FileName); | ||
Console.WriteLine(startInfo.Arguments); | ||
_process = new Process | ||
{ | ||
StartInfo = startInfo | ||
}; | ||
_process.ErrorDataReceived += (sender, eventArgs) => Console.Error.WriteLine(eventArgs.Data); | ||
_process.OutputDataReceived += (sender, eventArgs) => Console.WriteLine(eventArgs.Data); | ||
_process.Start(); | ||
_process.BeginErrorReadLine(); | ||
_process.BeginOutputReadLine(); | ||
_process.Exited += (sender, args) => { _process.Dispose(); }; | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.Error.WriteLine(e.StackTrace); | ||
throw; | ||
} | ||
break; | ||
case HostSignal.AfterActualRun: | ||
break; | ||
case HostSignal.BeforeAnythingElse: | ||
break; | ||
case HostSignal.AfterAll: | ||
break; | ||
case HostSignal.SeparateLogic: | ||
break; | ||
case HostSignal.BeforeProcessStart: | ||
break; | ||
case HostSignal.AfterProcessExit: | ||
break; | ||
default: | ||
throw new ArgumentOutOfRangeException(nameof(signal), signal, null); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
public IEnumerable<Metric> ProcessResults(DiagnoserResults results) => Enumerable.Empty<Metric>(); | ||
|
||
/// <inheritdoc /> | ||
public void DisplayResults(ILogger logger) { } | ||
|
||
/// <inheritdoc /> | ||
public IEnumerable<ValidationError> Validate(ValidationParameters validationParameters) => | ||
Enumerable.Empty<ValidationError>(); | ||
|
||
/// <inheritdoc /> | ||
public IEnumerable<string> Ids => new[] { nameof(DotTraceDiagnoser) }; | ||
|
||
/// <inheritdoc /> | ||
public IEnumerable<IExporter> Exporters => Enumerable.Empty<IExporter>(); | ||
|
||
public IEnumerable<IAnalyser> Analysers { get; } = Enumerable.Empty<IAnalyser>(); | ||
} | ||
} |
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,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>portable</DebugType> | ||
<DebugSymbols>true</DebugSymbols> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<Optimize>true</Optimize> | ||
<Configuration>Release</Configuration> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" /> | ||
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.11.5" /> | ||
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\samples\MediatR.Examples\MediatR.Examples.csproj" /> | ||
</ItemGroup> | ||
</Project> |
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,9 @@ | ||
using BenchmarkDotNet.Running; | ||
|
||
namespace MediatR.Benchmarks | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args); | ||
} | ||
} |