-
-
Notifications
You must be signed in to change notification settings - Fork 192
Expand file tree
/
Copy pathCacheAllocationChecks.cs
More file actions
60 lines (48 loc) · 1.83 KB
/
Copy pathCacheAllocationChecks.cs
File metadata and controls
60 lines (48 loc) · 1.83 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
// 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.
using System;
using System.Linq;
using Xunit;
namespace DynamicData.Profile
{
public class CacheAllocationChecks
{
[Fact]
public void PopulateCache_NoObservers()
{
var items = Enumerable.Range(1, 10_000).Select(j => new Person("P" + j, j)).ToList();
var cache = new SourceCache<Person, string>(p=>p.Name);
var result = Allocations.Run(() =>
{
cache.AddOrUpdate(items);
});
Console.WriteLine(result);
}
[Fact]
public void PopulateCache_Observers()
{
var items = Enumerable.Range(1, 10_000).Select(j => new Person("P" + j, j)).ToList();
var cache = new SourceCache<Person, string>(p => p.Name);
var subscribed = cache.Connect().Subscribe();
var result = Allocations.Run(() =>
{
cache.AddOrUpdate(items);
});
Console.WriteLine(result);
}
[Fact]
public void Connect()
{
var items = Enumerable.Range(1, 10_000).Select(j => new Person("P" + j, j)).ToList();
var cache = new SourceCache<Person, string>(p => p.Name);
cache.Connect().Subscribe();//do warm up
var added = Allocations.Run(() => cache.AddOrUpdate(items));
Console.WriteLine(added);
var connected = Allocations.Run(() => cache.Connect().Subscribe());
Console.WriteLine(connected);
var filtered = Allocations.Run(() => cache.Connect(p=>p.Age <5000).Subscribe());
Console.WriteLine(filtered);
}
}
}