-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Benchmarks Enhancements and Organization (#785)
* Fixed broken setup for displaying Benchmark artifacts in Solution Explorer. * Moved performance tests in the .Tests project over to the .Benchmarks project. * Fix Nullable errors in Benchmarks --------- Co-authored-by: Roland Pheasant <[email protected]> Co-authored-by: Chris Pulman <[email protected]>
- Loading branch information
1 parent
65bb022
commit e734087
Showing
11 changed files
with
192 additions
and
118 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reactive.Linq; | ||
|
||
using BenchmarkDotNet.Attributes; | ||
|
||
using DynamicData.Kernel; | ||
|
||
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.None<Person>()) | ||
.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; } | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reactive.Linq; | ||
|
||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace DynamicData.Benchmarks.Cache; | ||
|
||
[MemoryDiagnoser] | ||
[MarkdownExporterAttribute.GitHub] | ||
public class TransformMany | ||
{ | ||
[Benchmark] | ||
public void Perf() | ||
{ | ||
var children = Enumerable | ||
.Range(1, 10000) | ||
.Select(i => new Child( | ||
id: i, | ||
name: $"Child #{i}")) | ||
.ToArray(); | ||
|
||
var childIndex = 0; | ||
var parents = Enumerable | ||
.Range(1, 5000) | ||
.Select(i => new Parent( | ||
id: i, | ||
children: new[] | ||
{ | ||
children[childIndex++], | ||
children[childIndex++] | ||
})) | ||
.ToArray(); | ||
|
||
using var source = new SourceCache<Parent, int>(x => x.Id); | ||
|
||
using var subscription = source | ||
.Connect() | ||
.TransformMany(p => p.Children, c => c.Name) | ||
.Subscribe(); | ||
|
||
source.AddOrUpdate(parents); | ||
} | ||
|
||
private class Parent | ||
{ | ||
public Parent( | ||
int id, | ||
IEnumerable<Child> children) | ||
{ | ||
Id = id; | ||
Children = children.ToArray(); | ||
} | ||
|
||
public int Id { get; } | ||
|
||
public IReadOnlyList<Child> Children { get; } | ||
} | ||
|
||
private class Child | ||
{ | ||
public Child( | ||
int id, | ||
string name) | ||
{ | ||
Id = id; | ||
Name = name; | ||
} | ||
|
||
public int Id { get; } | ||
|
||
public string Name { get; } | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.