forked from reactiveui/ReactiveUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavigationStackBenchmark.cs
More file actions
114 lines (104 loc) · 3.24 KB
/
NavigationStackBenchmark.cs
File metadata and controls
114 lines (104 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reactive.Concurrency;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Order;
namespace ReactiveUI.Benchmarks
{
/// <summary>
/// Benchmarks for the NavigationStack and the RoutingState objects.
/// </summary>
[ClrJob]
[CoreJob]
[MemoryDiagnoser]
[MarkdownExporterAttribute.GitHub]
public class NavigationStackBenchmark
{
private static readonly Func<MockViewModel> _mockViewModel;
private RoutingState _router;
/// <summary>
/// Initializes static members of the NavigationStackBenchmark class.
/// </summary>
static NavigationStackBenchmark()
{
_mockViewModel = () => new MockViewModel();
}
/// <summary>
/// Setup method for when running all bench marks.
/// </summary>
[GlobalSetup]
public void Setup()
{
_router = new RoutingState(ImmediateScheduler.Instance);
}
/// <summary>
/// Performs the cleanup after all the benchmarks have been completed.
/// </summary>
[GlobalCleanup]
public void Cleanup()
{
_router.NavigationStack.Clear();
_router = null;
}
/// <summary>
/// Setup for each run of a benchmark.
/// </summary>
[IterationSetup]
public void IterationSetup()
{
_router.NavigationStack.Clear();
}
/// <summary>
/// Benchmark for when navigating to a new view model.
/// </summary>
[Benchmark]
public void Navigate()
{
using (_router.Navigate.Execute(_mockViewModel()).Subscribe())
{
_router.NavigationStack.ToList();
}
}
/// <summary>
/// Benchmark for when navigating and resetting to a new view model.
/// </summary>
[Benchmark]
public void NavigateAndReset()
{
using (_router.NavigateAndReset.Execute(_mockViewModel()).Subscribe())
{
_router.NavigationStack.ToList();
}
}
/// <summary>
/// Benchmark for when navigating back from a view model.
/// </summary>
[Benchmark]
public void NavigateBack()
{
using (_router.NavigateAndReset.Execute(_mockViewModel()).Subscribe())
using (_router.Navigate.Execute(_mockViewModel()).Subscribe())
using (_router.NavigateBack.Execute().Subscribe())
{
}
}
/// <summary>
/// Benchmark for when navigating and resetting the navigation stack.
/// </summary>
[Benchmark]
public void NavigationStack()
{
using (_router.NavigateAndReset.Execute(_mockViewModel()).Subscribe())
{
_router.NavigationStack.ToList();
}
}
/// <summary>
/// Benchmark creating our routing state.
/// </summary>
[SuppressMessage("usage", "CA1806: unused variable", Justification = "Used in the benchmark.")]
[Benchmark]
public void RoutingState() => new RoutingState();
}
}