Last active
October 15, 2021 09:03
-
-
Save gluck/da82c1b537e44b55daa8 to your computer and use it in GitHub Desktop.
Benchmark showing performance increase using FromEvent with conversion over FromEventPattern, using BenchmarkDotNet library
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
[BenchmarkTask(platform: BenchmarkPlatform.X86, jitVersion: BenchmarkJitVersion.LegacyJit)] | |
[BenchmarkTask(platform: BenchmarkPlatform.X64, jitVersion: BenchmarkJitVersion.LegacyJit)] | |
[BenchmarkTask(platform: BenchmarkPlatform.X64, jitVersion: BenchmarkJitVersion.RyuJit)] | |
public class FromEventBenchmark | |
{ | |
readonly Control control = new Control(); | |
[Benchmark] | |
public void FromEventPattern() | |
{ | |
Observable.FromEventPattern<EventHandler, EventArgs>(h => control.SizeChanged += h, h => control.SizeChanged -= h).Select(p => p.EventArgs) | |
.Publish().Connect().Dispose(); | |
} | |
[Benchmark] | |
public void FromEvent() | |
{ | |
Observable.FromEvent<EventHandler, EventArgs>(h => (sender, ea) => h(ea), h => control.SizeChanged += h, h => control.SizeChanged -= h) | |
.Publish().Connect().Dispose(); | |
} | |
} |
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
// ***** Competition: Finish ***** | |
// BenchmarkDotNet=v0.7.7.0 | |
// OS=Microsoft Windows NT 6.2.9200.0 | |
// Processor=Intel(R) Core(TM) i5-4300U CPU @ 1.90GHz, ProcessorCount=4 | |
// Host CLR=MS.NET 4.0.30319.42000, Arch=32-bit | |
Common: Type=FromEventBenchmark Mode=Throughput .NET=HostFramework | |
Method | Platform | Jit | AvrTime | StdDev | op/s | | |
----------------- |--------- |---------- |--------- |---------- |---------- | | |
FromEvent | X64 | LegacyJit | 3.71 us | 109.37 ns | 269718.74 | | |
FromEventPattern | X64 | LegacyJit | 12.63 us | 814.62 ns | 79178.01 | | |
FromEvent | X64 | RyuJit | 6.05 us | 379.20 ns | 165236.62 | | |
FromEventPattern | X64 | RyuJit | 18.53 us | 1.90 us | 53964.84 | | |
FromEvent | X86 | LegacyJit | 5.29 us | 54.17 ns | 189204.87 | | |
FromEventPattern | X86 | LegacyJit | 15.15 us | 531.08 ns | 66021.92 | | |
// ***** Competition: End ***** | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment