I have some code that looks like this:
public void SomeMethodThatLoadsUserData()
{
Stopwatch sw = new Stopwatch();
sw.Start();
Parallel.Invoke(Method1, Method2, .... , Method12);
sw.Stop();
var t = sw.ElapsedMilliseconds;
}
Each of these methods end up calling a query in the database. When I hit the Debug button, the first time this code runs it takes about 1200ms. And then, when I hit the restart button, after about 10 times, the result averages around 220ms.
Is this huge gap due to the fact that A) the first time the application must do some sort of compilation and the actual result on a production environment will be closer to the 220ms average I’m getting on my laptop or B) the data is cached in SQL server and when I hit the restart the data is read from cache and therefore the real performance of the method on a production environment will actually be closer to the 1200ms I see on the first run.
Thanks for your suggestion on how to read these figures.
This may be due to caching, depending on how you query your db (orm may cache, DB does caching, ..). There are a few things you have to consider: