Properties.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Reactive.Subjects;
  3. using BenchmarkDotNet.Attributes;
  4. namespace Avalonia.Benchmarks.Base
  5. {
  6. [MemoryDiagnoser]
  7. public class AvaloniaObjectBenchmark
  8. {
  9. private Class1 target = new Class1();
  10. private Subject<int> intBinding = new Subject<int>();
  11. public AvaloniaObjectBenchmark()
  12. {
  13. target.SetValue(Class1.IntProperty, 123);
  14. }
  15. [Benchmark]
  16. public void ClearAndSetIntProperty()
  17. {
  18. target.ClearValue(Class1.IntProperty);
  19. target.SetValue(Class1.IntProperty, 123);
  20. }
  21. [Benchmark]
  22. public void BindIntProperty()
  23. {
  24. using (target.Bind(Class1.IntProperty, intBinding))
  25. {
  26. for (var i = 0; i < 100; ++i)
  27. {
  28. intBinding.OnNext(i);
  29. }
  30. }
  31. }
  32. class Class1 : AvaloniaObject
  33. {
  34. public static readonly AvaloniaProperty<int> IntProperty =
  35. AvaloniaProperty.Register<Class1, int>("Int");
  36. }
  37. }
  38. }