Code slower in release mode..?

Con risposta Code slower in release mode..?

  • 2012年5月10日 22:41
     
     

    I recently re-wrote a binary file format library, since my old version was so terribly coded. My new library has proven to be twice as fast according to dotTrace and ANTS.

    But it's strange. I'll measure performance with the Stopwatch and its much, much slower than dotTrace and ANTS says it is.

    What's even more strange, is that I realized that the DEBUG build of my testing application (console app that just creates a new file with my library) is FASTER than the release build! 

    Testing with the Stopwatch class, the debug build runs at 00::00::00.042 on average. In the release build, it runs at 00::00::00.083 on average.

    Does anyone know why this might be happening?

    Thanks,

    Alex

全部回复

  • 2012年5月10日 22:56
     
     

    are you using XML serialize ?

    may be the below blog post applies ?

    http://blogs.msdn.com/b/billwert/archive/2008/02/23/use-of-sgen-exe-to-avoid-common-xmlserializer-performance-pitfalls.aspx


    Regards,
    Ahmed Ibrahim
    SQL Server Setup Team
    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you.
    This can be beneficial to other community members reading the thread.

  • 2012年5月10日 23:03
     
     

    Nope, no XML!

    I noticed that I get a performance 'boost' on the Release build when I have the Visual Studio host process enabled... Is that supposed to happen?

  • 2012年5月10日 23:11
     
     

    From

    http://msdn.microsoft.com/en-us/library/ms185331.aspx

    he hosting process is a feature in Visual Studio 2010 that improves debugging performance, enables partial trust debugging, and enables design time expression evaluation. The hosting process files contain vshost in the file name and are placed in the output folder of your project. For more information, see Debugging and the Hosting Process.


    Regards,
    Ahmed Ibrahim
    SQL Server Setup Team
    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you.
    This can be beneficial to other community members reading the thread.

  • 2012年5月10日 23:25
    版主
     
     建议的答复


    Testing with the Stopwatch class, the debug build runs at 00::00::00.042 on average. In the release build, it runs at 00::00::00.083 on average.

    Does anyone know why this might be happening?


    Try running this operation more than one time in the execution.

    I suspect the problem, especially given the timings, is that, when you run it in release, the first time your code runs, there will be some extra overhead as the JIT optimizes the code.

    This is common - when you're doing timings with a stopwatch, it's always a good idea to run your code once, then start the stopwatch and run it a second time.  Time the second (and subsequent) runs, as this will eliminate any JIT overhead.



    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

  • 2012年5月10日 23:45
     
     

    Reed,

    Those times are the averages I received after running each code 20 times (not including the first run).

  • 2012年5月11日 8:19
     
     

    are you running from visual studio?

    because even in release mode debugger is enabled,

    so you may try to disable this option from

    Tools > Options > Debugging > "Suppress JIT optimization on module load" 


    Regards,
    Ahmed Ibrahim
    SQL Server Setup Team
    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you.
    This can be beneficial to other community members reading the thread.

  • 2012年5月11日 22:28
     
     已答复

    Ahmed, nope, not running from Visual Studio, either.

    Thanks everyone for your help, regardless! I was able to chip the time down to 00::00::00.070, which I'm alright with. Not as fast as my C++ counterpart, but I'm pleased nevertheless. Thank you all for your help!

    -Alex

    • 已标记为答案 -Alex 2012年5月11日 22:29
    •