-6

I don't quite understand why you would just run your program without the debugger attached instead of running the test code without timing, then running the same code with timing. Sure this gives you a more even keeled test, but does it give you an absolute benchmark or is it just measuring raw performance?

It just seems that you aren't necessarily testing the performance as it would be run in a real world environment.

aledford
  • 15
  • 1
  • 1
    have a look here http://tech.pro/blog/1293/c-performance-benchmark-mistakes-part-one – Rune FS Jun 18 '13 at 18:03
  • When the debugger is attached, the runtime has to check, for every line of code, whether it's targeted by any breakpoints. And probably does many more things that cause an overhead that would deform the results. When measuring things, you want to get rid of as many confounding factors as possible. – millimoose Jun 18 '13 at 18:10

1 Answers1

3

The first few times you execute some code, the C# runtime is going to optimize it in the background - this is known as "JIT", or "Just in Time compiling". So if the code you're measuring is meant to be repeated many times - say, in a loop that's running 24h/24, then you want to measure how long it takes after the JIT is done, since that's what's going to be running most of the time.

redtuna
  • 4,586
  • 21
  • 35