Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 626
Daniel Frear Avatar asked Feb 14 '11 14:02

Daniel Frear


1 Answers

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.

like image 84
Davide Piras Avatar answered Nov 12 '22 21:11

Davide Piras