10

I am getting a strange output because of profiling my code. For the main calculation of code it correctly shows that more that 70% of time has been spent on those parts but there are some other interesting points. The following line takes %5.8

int counter = 0 ; // %5.8 of total time

and the following For loop has less time consumption (nx = 800 & ny=800)! How this is possible? Picture of the profiler result was attached. enter image description here

Mehdi
  • 211
  • 2
  • 11
  • What profiler is this? – TyCobb Aug 08 '14 at 03:44
  • 8
    is it possible the first call assigning the int is jitting the rest of the code perhaps, my assumption would be the extra time is due to code being jit compiled, try running the code twice in the profiled and see if the second call takes the same amount of thime, that will answer the JIT question :) – sa_ddam213 Aug 08 '14 at 03:44
  • @sa_ddam213 : what does jitting mean? I even couldn't find it on dictionary. – Mehdi Aug 08 '14 at 03:48
  • 2
    Just In Time compiling, http://www.c-sharpcorner.com/UploadFile/nipuntomar/jit-just-in-time-compiler/ – sa_ddam213 Aug 08 '14 at 03:48
  • 1
    @TyCobb: CPU sampling - VS performance and diagnostics – Mehdi Aug 08 '14 at 03:49
  • That's why [*this method*](http://stackoverflow.com/a/378024/23771) keeps getting votes. – Mike Dunlavey Aug 10 '14 at 00:57
  • Medhi, perhaps the use of VS.net Profiler in Sampling mode is causing a misreported result. Can you reproduce the same problem in Instrumented mode ? – PhillipH Aug 11 '14 at 13:36
  • Is that line of code the first line of code in your `Main` function? If it is it could be lumping in all the time leading up to your program lunching in that first line's "Cost". – Scott Chamberlain Aug 27 '14 at 16:35

2 Answers2

1

Better way to test is to attach the profiler but don't start it yet. (This looks like VS profiler which I know will do this.) Run the code, then start the profiler and run it again (or multiple times). This will give you a much better picture of what the code is doing (unless you're TRYING to measure start-up performance).

Kyle W
  • 3,702
  • 20
  • 32
0

I would hazard a guess that this is due to the JIT compiler. try causing your code to run through the offending line twice and check if it has the same performance impact.

Assaf
  • 1,352
  • 10
  • 19