Skip to content

Commit

Permalink
Merge pull request #236 from runceel/main
Browse files Browse the repository at this point in the history
Release v7.8.0
  • Loading branch information
runceel authored Feb 21, 2021
2 parents ba56b5b + f5b8727 commit 8852ef1
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 140 deletions.
19 changes: 19 additions & 0 deletions Benchmark/FromEventBenchmark.Rp/FromEventBenchmark.Rp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>FromEventBenchmark</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Source\ReactiveProperty.NETStandard\ReactiveProperty.NETStandard.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\FromEventBenchmark.Rx\*.cs" />
</ItemGroup>
</Project>
14 changes: 14 additions & 0 deletions Benchmark/FromEventBenchmark.Rx/FromEventBenchmark.Rx.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>FromEventBenchmark</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="ReactiveProperty" Version="7.7.1" />
</ItemGroup>

</Project>
74 changes: 74 additions & 0 deletions Benchmark/FromEventBenchmark.Rx/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.ComponentModel;
using System.Linq;
using System.Reactive.Disposables;
using System.Threading;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using Reactive.Bindings.Extensions;

/*
FromEventBenchmark.Rx
| Method | Count | Mean | Error | StdDev |
|---------------- |------- |------------------:|----------------:|----------------:|
| ObserveProperty | 1 | 4.662 us | 0.0403 us | 0.0377 us |
| ObserveProperty | 10 | 46.159 us | 0.2482 us | 0.2322 us |
| ObserveProperty | 100 | 488.395 us | 3.9745 us | 3.7177 us |
| ObserveProperty | 1000 | 7,299.851 us | 49.5364 us | 41.3651 us |
| ObserveProperty | 10000 | 184,803.556 us | 2,443.4350 us | 2,285.5906 us |
| ObserveProperty | 100000 | 21,848,008.562 us | 183,192.5623 us | 152,974.0864 us |
FromEventBenchmark.Rp
| Method | Count | Mean | Error | StdDev |
|---------------- |------- |---------------:|--------------:|--------------:|
| ObserveProperty | 1 | 3.313 us | 0.0226 us | 0.0200 us |
| ObserveProperty | 10 | 32.927 us | 0.2260 us | 0.2114 us |
| ObserveProperty | 100 | 335.572 us | 2.0898 us | 1.9548 us |
| ObserveProperty | 1000 | 4,245.384 us | 82.0820 us | 91.2340 us |
| ObserveProperty | 10000 | 79,851.266 us | 1,057.3668 us | 937.3281 us |
| ObserveProperty | 100000 | 779,906.493 us | 8,120.6971 us | 7,596.1051 us |
*/

BenchmarkRunner.Run(typeof(FromEventBenchmark).Assembly);

public class FromEventBenchmark
{
[Params(1, 10, 100, 1000, 10000, 100000)]
public int Count { get; set; }

public FromEventBenchmark()
{
SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
}

[Benchmark]
public IDisposable ObserveProperty()
{
var d = new CompositeDisposable();
foreach (var _ in Enumerable.Range(0, Count))
{
var obj = new ObservableObject();
obj.ObserveProperty(x => x.Prop)
.Subscribe()
.AddTo(d);
obj.Prop = "Trigger an event";
}

return d;
}
}

class ObservableObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _prop;
public string Prop
{
get => _prop;
set
{
_prop = value;
PropertyChanged?.Invoke(this, new(nameof(Prop)));
}
}
}
14 changes: 13 additions & 1 deletion Benchmark/ReactiveProperty-Benchmark.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmark.V6", "Benchmark.V
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmark.Current", "Benchmark.Current\Benchmark.Current.csproj", "{B25D15DD-44CA-48BF-8469-F28C9BB67431}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmark.V7", "Benchmark.V7\Benchmark.V7.csproj", "{333DFAE9-1172-4BE6-A73C-5907B3E8D8FC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmark.V7", "Benchmark.V7\Benchmark.V7.csproj", "{333DFAE9-1172-4BE6-A73C-5907B3E8D8FC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FromEventBenchmark.Rx", "FromEventBenchmark.Rx\FromEventBenchmark.Rx.csproj", "{13FE8962-493E-4A93-BA72-673FD03BFE79}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FromEventBenchmark.Rp", "FromEventBenchmark.Rp\FromEventBenchmark.Rp.csproj", "{994EBA52-18E1-4677-9FD5-5F9056DE8D85}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -41,6 +45,14 @@ Global
{333DFAE9-1172-4BE6-A73C-5907B3E8D8FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{333DFAE9-1172-4BE6-A73C-5907B3E8D8FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{333DFAE9-1172-4BE6-A73C-5907B3E8D8FC}.Release|Any CPU.Build.0 = Release|Any CPU
{13FE8962-493E-4A93-BA72-673FD03BFE79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{13FE8962-493E-4A93-BA72-673FD03BFE79}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13FE8962-493E-4A93-BA72-673FD03BFE79}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13FE8962-493E-4A93-BA72-673FD03BFE79}.Release|Any CPU.Build.0 = Release|Any CPU
{994EBA52-18E1-4677-9FD5-5F9056DE8D85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{994EBA52-18E1-4677-9FD5-5F9056DE8D85}.Debug|Any CPU.Build.0 = Debug|Any CPU
{994EBA52-18E1-4677-9FD5-5F9056DE8D85}.Release|Any CPU.ActiveCfg = Release|Any CPU
{994EBA52-18E1-4677-9FD5-5F9056DE8D85}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reactive.Linq;
using System.Reactive.Concurrency;
using System.Windows.Input;
using Reactive.Bindings.Internals;

namespace Reactive.Bindings.Extensions
{
Expand All @@ -14,7 +15,7 @@ public static class ICommandExtensions
/// </summary>
public static IObservable<EventArgs> CanExecuteChangedAsObservable<T>(this T source)
where T : ICommand =>
Observable.FromEvent<EventHandler, EventArgs>(
InternalObservable.FromEvent<EventHandler, EventArgs>(
h => (sender, e) => h(e),
h => source.CanExecuteChanged += h,
h => source.CanExecuteChanged -= h);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class INotifyCollectionChangedExtensions
/// </summary>
public static IObservable<NotifyCollectionChangedEventArgs> CollectionChangedAsObservable<T>(this T source)
where T : INotifyCollectionChanged =>
Observable.FromEvent<NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs>(
InternalObservable.FromEvent<NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs>(
h => (sender, e) => h(e),
h => source.CollectionChanged += h,
h => source.CollectionChanged -= h);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class INotifyDataErrorInfoExtensions
/// </summary>
public static IObservable<DataErrorsChangedEventArgs> ErrorsChangedAsObservable<T>(this T subject)
where T : INotifyDataErrorInfo =>
Observable.FromEvent<EventHandler<DataErrorsChangedEventArgs>, DataErrorsChangedEventArgs>(
InternalObservable.FromEvent<EventHandler<DataErrorsChangedEventArgs>, DataErrorsChangedEventArgs>(
h => (sender, e) => h(e),
h => subject.ErrorsChanged += h,
h => subject.ErrorsChanged -= h);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class INotifyPropertyChangedExtensions
/// </summary>
public static IObservable<PropertyChangedEventArgs> PropertyChangedAsObservable<T>(this T subject)
where T : INotifyPropertyChanged =>
Observable.FromEvent<PropertyChangedEventHandler, PropertyChangedEventArgs>(
InternalObservable.FromEvent<PropertyChangedEventHandler, PropertyChangedEventArgs>(
h => (sender, e) => h(e),
h => subject.PropertyChanged += h,
h => subject.PropertyChanged -= h);
Expand Down
Loading

0 comments on commit 8852ef1

Please sign in to comment.