3 ms·
Changed 6 to 7 in my project file, the program started running 10% slower ... hmm. Specifically, 5 1107ms 6 1075ms 7 1211ms Just number crunching and callin
by EVa5I7bHFq9mnYK 4y ago
Changed 6 to 7 in my project file, the program started running 10% slower ... hmm. Specifically,
5 1107ms
6 1075ms
7 1211ms
Just number crunching and calling HashSet.
- neonsunset 4y agoIf you are using `time` and calculate the time from application startup to exit 0 then it is not representative of performance of the code itself - more aggressive optimization in JIT tend to have increasing cost with each release even if the people working on it try to always ensure the compilation throughput stays constant and we get more optimized JIT code per same amount of CPU work. If you would like to have representative benchmark data, I suggest relying on BenchmarkDotNet instead.
- EVa5I7bHFq9mnYK 4y agoI was using Stopwatch around the loop.
- EVa5I7bHFq9mnYK 4y agoLooking further into it (I really want my program to run faster!), looks like 7 produces unoptimized code. Could it be that it decided for me that I want faster startup vs faster code? Can I force it to turn optimizations on somehow?
- neonsunset 4y agoIf you do only a couple of iterations it will not optimize it. Loops can be now optimized in-flight thanks to on-stack replacement feature which should help with startup time and also allow to apply Tier-1 compilation with more optimizations should the loop become hot (e.g. can't elide static initialization checks if you go straight to full optimized without Tier 0 -> Tier 1). To get more representative data it is best to either use BenchmarkDotNet or profile code close to real life case.
- EVa5I7bHFq9mnYK 4y agoI see. So I just inserted <TieredCompilation>false</TieredCompilation> into project file and it fixed it. Runs as fast as 6.
- neonsunset 4y agoPlease do not use this. JIT is designed with tiered compilation in mind for a long time. I cannot stress this enough, the number in the above comment is not representative. Using this setting is highly discouraged. Please use BenchmarkDotNet to get accurate numbers!
- EVa5I7bHFq9mnYK 4y agomy program's main purpose is not running benchmarks)
- neonsunset 4y agoThere is no doubt but if you would like to accurately compare a part of your code on 6 vs 7 then the best practice is to use BDN with [SimleJob(RuntimeMoniker.Net60)] and [SimleJob(RuntimeMoniker.Net70)]. Make sure to set project to multi-target both versions. That way you will see actual difference, feel free to also add [MemoryDiagnoser] and [DisassemblyDiagnoser(exportCombinedDisassemblyReport: true)].
- andyayers 4y agoFeel free to open an issue for this over at github.com/dotnet/runtime, if you have code you can share.
- Izikiel43 4y agoUse benchmark.net for tests and come back