Why is my code faster when running with Performance Analysis?
I've got a bit of a conundrum here. I have been trying to speed up a certain function, now when I run my application it takes ~16-17 seconds to run this function.
Now if I run the same with Performance Analysis running alongside it in VS2010, in order to find the slower sections, the code executes in ~6-7 seconds. Now, if my code did run this fast, 开发者_运维知识库that would be perfectly acceptable for the application.
I've tried running the code (without perf analysis) via both debug and release profiles, with little to no difference.
Anyone got any ideas what may be occurring here?
Few notes: the function in question uses quite a lot of LINQ to SQL and the performance analysis im using is CPU Sampling.
I believe you should focus on the slowest parts of your code and optimize them anyway if you identify what takes longer than other parts, don't care of the absolute duration in seconds but just think relative.
Even if you see the whole application is executed in 7 seconds, if there are methods which take 40% of this whole time try to optimize them then you will surely profit of this fine tuning even without Performance Analysis enabled and the total execution time will drop even more if initially it was around 17 seconds.
Do you see a lot of dll's being loaded as you enter the function in the non performance analysis case? I wonder if entering this function is causing a lot of dlls to load, that in the performance analysis case have already been loaded earlier.
精彩评论