-
-
Notifications
You must be signed in to change notification settings - Fork 192
Expand file tree
/
Copy pathEditDiff.cs
More file actions
67 lines (60 loc) · 1.94 KB
/
Copy pathEditDiff.cs
File metadata and controls
67 lines (60 loc) · 1.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
namespace DynamicData.Benchmarks.Cache;
[MemoryDiagnoser]
[MarkdownExporterAttribute.GitHub]
public class EditDiff
{
public const int MaxItems
= 1097;
[Benchmark]
[Arguments(7, 3, 5)]
[Arguments(233, 113, MaxItems)]
[Arguments(233, 0, MaxItems)]
[Arguments(233, 233, MaxItems)]
[Arguments(2521, 1187, MaxItems)]
[Arguments(2521, 0, MaxItems)]
[Arguments(2521, 2521, MaxItems)]
[Arguments(5081, 2683, MaxItems)]
[Arguments(5081, 0, MaxItems)]
[Arguments(5081, 5081, MaxItems)]
public void AddsRemovesAndUpdates(int collectionSize, int updateSize, int maxItems)
{
using var subscription = Enumerable
.Range(1, maxItems - 1)
.Select(n => n * (collectionSize - updateSize))
.Select(index => Person.CreateRange(index, updateSize, "Overlap")
.Concat(Person.CreateRange(index + updateSize, collectionSize - updateSize, "Name")))
.Prepend(Person.CreateRange(0, collectionSize, "Name"))
.ToObservable()
.EditDiff(p => p.Id)
.Subscribe();
}
[Benchmark]
[Arguments(7)]
[Arguments(MaxItems)]
public void OptionalAddsAndRemoves(int maxItems)
{
using var subscription = Enumerable
.Range(0, MaxItems)
.Select(n => (n % 2) == 0
? new Person(n, "Name")
: Optional<Person>.None)
.ToObservable()
.EditDiff(p => p.Id)
.Subscribe();
}
private class Person
{
public static IReadOnlyList<Person> CreateRange(int baseId, int count, string baseName)
=> Enumerable
.Range(baseId, count)
.Select(i => new Person(i, baseName + i))
.ToArray();
public Person(int id, string name)
{
Id = id;
Name = name;
}
public int Id { get; }
public string Name { get; }
}
}