Launching VS Profiler boosts Application Performance x20?

后端 未结 4 1229
情深已故
情深已故 2021-02-03 14:01

EDIT 1
I do not exclude at all this might be caused by something very basic side effect of using the Profiler (some faulty setting in my \"regular\" pro

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-03 14:54

    Considering that the question is about code running faster under the profiler, and that the specific questions are "1. WHAT EXACTLY HAPPENS, HOW, and WHY ? and 2. How to make my code behave like that natively ?" the accepted answer is wrong, since it does not address the profiler at all, nor does it mention the specific cause of the 20x speed up.

    What exactly happens is this:

    In the "Debug" tab of your project properties the "Enable unmanaged code debugging" check box is checked; this option causes the debugger to be slow as molasses.

    When you run the profiler, it is still the debug version of your program which you are profiling, so the "DEBUG" symbol is defined, and all the tracing, assertions, etc. are enabled, but the debugger is not involved, so the "Enable unmanaged code debugging" option is not applicable. (JIT optimizations are probably enabled while profiling, but that would not account for even a 2x performance boost, let alone a 20x boost.)

    If you want to enjoy this 20x boost while debugging your code, (not only while profiling,) go to the "Debug" tab of your project properties and make sure that "Enable unmanaged code debugging" is unchecked.

    P.S.

    There is a question which is a few-month-older duplicate of this one: How Come when I sampling profile a program and it actually runs faster than not profiling?

提交回复
热议问题