-
Notifications
You must be signed in to change notification settings - Fork 11
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
Optimize for performance #11
Comments
I haven't investigate much yet but I think most of CPU time is actually used by memory allocations and this causes pressure for garbage collector. (edit, was wrong benchmark implementation) BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19043.1526 (21H1/May2021Update)
Intel Core i7-4600U CPU 2.10GHz (Haswell), 1 CPU, 4 logical and 2 physical cores
.NET SDK=6.0.100-rc.2.21505.57
[Host] : .NET Core 3.1.20 (CoreCLR 4.700.21.47003, CoreFX 4.700.21.47101), X64 RyuJIT
Job=InProcess Toolchain=InProcessEmitToolchain
|
I already have some progress, its not much but a few percent improvement. Memory pressure has also degreased quite a bit and conversion back to SI units doesn't allocate any more memory (in case of Temperature unit). I replaced in UnitSystem.cs Tuple reference object with Tuple value object in - public List<Tuple<string,int>> UnitsCount()
+ public List<(string Key, int Value)> UnitsCount()
{
//This returns <typeOfUnit,Unit Count of the specifig type>
//var test = ListOfUnits
// .Where(x => x.TypeOfUnit != "CombinedUnit")
@@ -58,55 +58,79 @@ namespace EngineeringUnits
return ListOfUnits
.Where(x => x.TypeOfUnit != "CombinedUnit")
.GroupBy(x => x.TypeOfUnit)
- .Select(x => new Tuple<string, int>(x.Key, x.Sum(x => x.Count)))
- .Where(x=> x.Item2 != 0)
+ .Select(x => (x.Key, x.Sum(x => x.Count)))
+ .Where(x => x.Item2 != 0)
.ToList();
}
public static bool operator ==(UnitSystem a, UnitSystem b)
{
- return a.UnitsCount().All(b.UnitsCount().Contains) &&
- a.UnitsCount().Count == b.UnitsCount().Count;
+ var aUnitsCount = a.UnitsCount();
+ var bUnitsCount = b.UnitsCount();
+
+ if (aUnitsCount.Count != bUnitsCount.Count)
+ return false;
+
+ return aUnitsCount.All(bUnitsCount.Contains);
} BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19043.1526 (21H1/May2021Update)
Intel Core i7-4600U CPU 2.10GHz (Haswell), 1 CPU, 4 logical and 2 physical cores
.NET SDK=6.0.100-rc.2.21505.57
[Host] : .NET Core 3.1.20 (CoreCLR 4.700.21.47003, CoreFX 4.700.21.47101), X64 RyuJIT
DefaultJob : .NET Core 3.1.20 (CoreCLR 4.700.21.47003, CoreFX 4.700.21.47101), X64 RyuJIT
|
I have optimized some code, included with your code. The list I have so fare of future optimizations:
Edit: Running the same tests after the upgrades I just did (On a faster PC..)
I have never used this benchmark system but it looks awesome! |
I can give a try, but I need to use same environment than earlier. Have you some kind tests in mind what we should try to test. Micro benchmarking is slow process so it would be nice to if we have some plan what operations we should focus. You know best anatomy of library and internals how they works :) I had worries about how fast or memory hog Fraction type is but it seems that it's not a bottle neck. It's implemented as value type, no unnecessary memory allocations and calculations seems to be quite fast. |
Just fetched your latest version and speed and memory allocations looks much better than yesterday. Specially memory allocations, which doesn't depend CPU, has been reduced dramatically, nice!
I forget show last test what I used which constructs
This is first time when I used any type of benchmarking and this was good way to learn how to use BenchmarkDotNet. It's very nice tool and I should start to use it more. |
I just did speed test:
1mio calculations in 0.240 sec (on my computer). Of cause if you do your calculation in double you can get much faster then this |
I would like to start a discussion about how we can optimize for better performance.
Feel free to chip in!
Analyse where the CPU is spending much of the time?
--> Can we write better code that fixes the heavy CPU using functions?
Could we implement new strategies?
--> fx. If two units are Set as SI we could ship Unitchecks and other parts of the system
The text was updated successfully, but these errors were encountered: