-
-
Notifications
You must be signed in to change notification settings - Fork 192
Expand file tree
/
Copy pathDisposeMany_Cache.cs
More file actions
55 lines (47 loc) · 1.54 KB
/
Copy pathDisposeMany_Cache.cs
File metadata and controls
55 lines (47 loc) · 1.54 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
// Copyright (c) 2011-2019 Roland Pheasant. All rights reserved.
// Roland Pheasant licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
namespace DynamicData.Benchmarks.Cache
{
[MemoryDiagnoser]
[MarkdownExporterAttribute.GitHub]
public class DisposeMany_Cache
{
[Benchmark]
[Arguments(1, 0)]
[Arguments(1, 1)]
[Arguments(10, 0)]
[Arguments(10, 1)]
[Arguments(10, 10)]
[Arguments(100, 0)]
[Arguments(100, 1)]
[Arguments(100, 10)]
[Arguments(100, 100)]
[Arguments(1_000, 0)]
[Arguments(1_000, 1)]
[Arguments(1_000, 10)]
[Arguments(1_000, 100)]
[Arguments(1_000, 1_000)]
public void AddsRemovesAndFinalization(int addCount, int removeCount)
{
using var source = new SourceCache<KeyedDisposable, int>(static item => item.Id);
using var subscription = source
.Connect()
.DisposeMany()
.Subscribe();
for(var i = 0; i < addCount; ++i)
source.AddOrUpdate(new KeyedDisposable(i));
for(var i = 0; i < removeCount; ++i)
source.RemoveKey(i);
subscription.Dispose();
}
private sealed class KeyedDisposable
: IDisposable
{
public KeyedDisposable(int id)
=> Id = id;
public int Id { get; }
public void Dispose() { }
}
}
}