Properties.cs 1.1 KB

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