-
Notifications
You must be signed in to change notification settings - Fork 731
Optimizations #817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimizations #817
Conversation
|
Could we perhaps add some benchmark tests to the repo similar to the ones you ran? |
|
What did you use? DotTrace? |
|
I used the builtin profiler in Visual Studio 2017. |
|
@Meir017 Do you have an idea how to structure this? My thoughts:
|
|
yup 👍 I was thinking of maybe using existing tests and executing them multiple times public class CollectionEquivalencySpecsBenchmark
{
public CollectionEquivalencySpecs Subject { get; }
public CollectionEquivalencySpecsBenchmark()
{
Subject = new CollectionEquivalencySpecs();
}
[Benchmark]
public void When_a_collection_does_not_match_it_should_include_items_in_message()
=> Subject.When_a_collection_does_not_match_it_should_include_items_in_message();
}and of course we could generate this code :) |
|
Now let's hope AppVeyor uses the same kind of machine every time. |
|
I wouldn't count on AppVeyor using the same kind of machine every time. The best approach I can currently think of, it setting up a benchmark baseline before doing improvements and running it locally before and after to verify improvements. Ideally it would require a dedicated benchmark machine, but I think that's out of scope. |
95a6c96 to
de9cdbd
Compare
|
I'll be adding more benchmarks before merging this, but here are the results of before and after the Before: |
|
TLDR;
baseline: Cache Deletegate - 4140064 Combine Linq expressions - 6c0adea Cast enumerable to list/collection - e01e0d7 Optimize HasValueSemantics - 9abdff3 Use a list of unmatched indexes - cd719c3 Combine() - 3d3cca7 Cache HasValueSemantics - 95738ed Cache OverridesEquals - 12bd297 |
I tried to benchmark
BeEquivalentToas that seems to the most heavy assertion due to heavy use of reflection.The most visible bottleneck was recreating the delegate for
TraceBlockinLooselyMatchAgainstin each iteration, instead of caching it.It used 24.15% of the time.
There are also a lot of places, where we convert an
IEnumerableto a new Array/List, but it seems we could just cast the object if it actually is anICollectionorIList,So I created helper functions
ConvertOrCastToCollectionandConvertOrCastToListto help reduce the amount of unnecessary copying.Here's the code I used to test two lists of 20.000 identical 6-nested objects.