Last active
November 7, 2017 21:43
-
-
Save RolandPheasant/11bb56dd0ef110dec3dde4bc77e120f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ListFilterPerf | |
{ | |
private static readonly ICollection<int> Items = Enumerable.Range(1, 1_000_000).ToList(); | |
[Fact] | |
public void ListOnly_Range() | |
{ | |
using (var list = new SourceList<int>()) | |
{ | |
list.AddRange(Items); | |
} | |
} | |
[Fact] | |
public void ListOnly_Many() | |
{ | |
using (var list = new SourceList<int>()) | |
{ | |
foreach (var item in Items) | |
list.Add(item); | |
} | |
} | |
[Fact] | |
public void Filter_RangeBeforeSubscribe() | |
{ | |
using (var list = new SourceList<int>()) | |
{ | |
list.AddRange(Items); | |
list.Connect().Filter(v => v % 2 == 0).Subscribe(v => { }); | |
} | |
} | |
[Fact] | |
public void Filter_ItemsBeforeSubscribe() | |
{ | |
using (var list = new SourceList<int>()) | |
{ | |
foreach (var item in Items) | |
list.Add(item); | |
list.Connect().Filter(v => v % 2 == 0).Subscribe(v => { }); | |
} | |
} | |
[Fact] | |
public void Filter_ItemsAfterSubscribe() | |
{ | |
using (var list = new SourceList<int>()) | |
{ | |
list.Connect().Filter(v => v % 2 == 0).Subscribe(v => { }); | |
foreach (var item in Items) | |
list.Add(item); | |
} | |
} | |
[Fact] | |
public void Filter_RangeAfterSubscribe() | |
{ | |
using (var list = new SourceList<int>()) | |
{ | |
list.Connect().Filter(v => v % 2 == 0).Subscribe(v => { }); | |
list.AddRange(Items); | |
} | |
} | |
[Fact] | |
public void BufferInitial() | |
{ | |
var sheduler = new TestScheduler(); | |
using (var list = new SourceList<int>()) | |
{ | |
int count = 0; | |
list.Connect() | |
.BufferInitial(TimeSpan.FromMilliseconds(250), sheduler) | |
.Filter(v => v % 2 == 0) | |
.Subscribe(v => { count = v.TotalChanges; }); | |
foreach (var item in Items) | |
list.Add(item); | |
sheduler.AdvanceBy(TimeSpan.FromMilliseconds(251).Ticks); | |
count.Should().Be(500_000); | |
list.Add(2); | |
count.Should().Be(1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment