forked from reactiveui/ReactiveUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateReactiveListBenchmark.cs
More file actions
81 lines (72 loc) · 2.94 KB
/
CreateReactiveListBenchmark.cs
File metadata and controls
81 lines (72 loc) · 2.94 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
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
using System.Collections.Generic;
using System.Collections.ObjectModel;
using BenchmarkDotNet.Attributes;
using DynamicData;
using DynamicData.Binding;
using ReactiveUI.Legacy;
#pragma warning disable CS0618 // Item is obsolete warning
namespace ReactiveUI.Benchmarks.Legacy
{
/// <summary>
/// Creates bench marks to the deprecated ReactiveList. This allows us to compare to the DynamicData approach.
/// </summary>
[ClrJob]
[CoreJob]
[MemoryDiagnoser]
[MarkdownExporterAttribute.GitHub]
public class CreateReactiveListBenchmark
{
private static readonly string[] _testData =
{
"ReactiveUI",
"ReactiveUI.XamForms",
"ReactiveUI.WPF",
"ReactiveUI.Events",
"ReactiveUI",
"ReactiveUI.XamForms",
"ReactiveUI.WPF",
"ReactiveUI.Events"
};
/// <summary>
/// Benchmarks using a System.Collections.Generic.List class as our base benchmark.
/// </summary>
/// <returns>The created list.</returns>
[Benchmark(Baseline = true)]
public object CreateList() => new List<string>();
/// <summary>
/// Benchmark using the ObservableCollection class to compare against.
/// </summary>
/// <returns>The created list.</returns>
[Benchmark]
public object CreateObservableCollection() => new ObservableCollection<string>(_testData);
/// <summary>
/// Benchmark using the legacy ReactiveList interface.
/// </summary>
/// <returns>The cretaed list.</returns>
[Benchmark]
public object CreateReactiveList() => new ReactiveList<string>(_testData);
/// <summary>
/// Benchmark using the ObservableCollection class wrapped in a ReadOnlyObservableCollection.
/// </summary>
/// <returns>The created list.</returns>
[Benchmark]
public object CreateReadOnlyObservableList() =>
new ReadOnlyObservableCollection<string>(new ObservableCollection<string>(_testData));
/// <summary>
/// Benchmark using the ObservableCollection class wrapped in a ReadOnlyObservableCollection.
/// </summary>
/// <returns>The created list.</returns>
[Benchmark]
public object CreateObservableCollectionExtended() => new ObservableCollectionExtended<string>(_testData);
/// <summary>
/// Benchmark using the source list class from DynamicData.
/// </summary>
/// <returns>The created list.</returns>
[Benchmark]
public object CreateSourceList() => new SourceList<string>().Connect().AsObservableList();
}
}