Browse Source

Added some benchmarks

Added some benchmarks to test setting and binding properties.
pull/856/head
Steven Kirk 8 years ago
parent
commit
4f8f5e9c71
  1. 1
      tests/Avalonia.Benchmarks/Avalonia.Benchmarks.csproj
  2. 43
      tests/Avalonia.Benchmarks/Base/Properties.cs

1
tests/Avalonia.Benchmarks/Avalonia.Benchmarks.csproj

@ -49,6 +49,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Base\Properties.cs" />
<Compile Include="Layout\Measure.cs" />
<Compile Include="Styling\ApplyStyling.cs" />
<Compile Include="Program.cs" />

43
tests/Avalonia.Benchmarks/Base/Properties.cs

@ -0,0 +1,43 @@
using System;
using System.Reactive.Subjects;
using BenchmarkDotNet.Attributes;
namespace Avalonia.Benchmarks.Base
{
[MemoryDiagnoser]
public class AvaloniaObjectBenchmark
{
private Class1 target = new Class1();
private Subject<int> intBinding = new Subject<int>();
public AvaloniaObjectBenchmark()
{
target.SetValue(Class1.IntProperty, 123);
}
[Benchmark]
public void ClearAndSetIntProperty()
{
target.ClearValue(Class1.IntProperty);
target.SetValue(Class1.IntProperty, 123);
}
[Benchmark]
public void BindIntProperty()
{
using (target.Bind(Class1.IntProperty, intBinding))
{
for (var i = 0; i < 100; ++i)
{
intBinding.OnNext(i);
}
}
}
class Class1 : AvaloniaObject
{
public static readonly AvaloniaProperty<int> IntProperty =
AvaloniaProperty.Register<Class1, int>("Int");
}
}
}
Loading…
Cancel
Save