Visual Studio C# 2010 Express Debug running Faster than Release

我的未来我决定 提交于 2019-12-05 04:23:10

I don't see anything in there to say that you are selecting release build. This is an option on the toolbar. If you are directly running a debug build maybe it is looking for something it can't find.

EDIT: except the title which I missed!!!! :-)

So first up, you should do some performance profiling. Either use a profiling tool or just use a timer to print out some messages somewhere showing how long certain things take - this should allow you to at least nail down what line of code is running slowly even if it doesn't tell you why its running so much slower under the debugger. Without this information all you have is guesswork.

Now, onto the guesswork...

I think the problem has something to do with the use of the console, based on these observations

  • Writing to the console window itself is actually relatively slow - you can see this when running an application which writes a lot of stuff to the console. If you keep the window open then it takes a long time to run, however if you minimize the console window the same operation can run a lot quicker.
  • As I understand it you are writing 1 message to the console every 0.35ms. Thats a lot of messages.
  • Depending on how you are running your application Visual Studio actually redirects the console output to the "Output" window inside Visual Studo when debugging.

My guess is that the console window in Visual Studio is a lot quicker than the equivalent mechanism used when not debugging, and that the cause of the additional slowdown is actually your logging code. Try taking out your console based logging and log to a file instead to see if it makes any difference, or even just reduce the number of times you log messages e.g. log the time it takes to complete 100 iterations - this will reduce the impact (if any) that the console is having on your performance.

The problem has nothing to do with HyperThreading. I can't find the link, but there is a nice technical description from 2004 from Intel on how that works (without any marketing hype). But the short of it is: Core 0 is probably a real core and Core 1 is probably a logical core sharing the same hardware as Core 0. For our perspective (app devs), both Cores 0 and 1 are real and we don't have to care about the fact that Core 1 is a logical core (except for the obvious, the logical core only gives a rough 13-30% perf boost overall, again that's mentioned in the technical description). Windows does a pretty good job of scheduling threads across real and logical cores. All you would have to do is to create two threads, and Windows would run one each on Cores 0 and 1. You can disable HyperThreading in the BIOS, programmatically set processor affinity for your threads, or set affinity from Task Manager, if you want to experiment.

That being said, experimenting with HyperThreading won't help you solve your problem. You should do as already mentioned and profile the release build. Also look for weird errors in the Event Log. And run sysinternal's Process Explorer to see if way too much time is spent in I/O. Who knows, perhaps the release build is somehow triggering some quirky behavior in a device driver on this machine.

EDIT: Here is Intel's tech description (yay Wikipedia), is actually from 2002: http://download.intel.com/technology/itj/2002/volume06issue01/vol6iss1_hyper_threading_technology.pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!