简体   繁体   中英

Running Visual Studio console application in debug mode consumes no more than 50 percent cpu usage

I have a several C# console applications that basically parse tons of data in memory (LINQ) and output the results to a text file.

Now, forget about the writing to the text file for a minute because this is not where the problem is occurring.

When I run the application in debug mode, I will never get it to utilize more than 50% of cpu usage. It will be parsing/massaging hundreds of thousands of records, but only go X fast and utilize 50% of the cpu AT MOST (as viewed in the Task Manager).

I would really like to use 100% of the CPU to make the processing go faster.

Does anybody have any insight?

I am running Windows XP Professional with Service Pack 3. I have Visual Studio 2008 Professional with Service Pack 1 installed.

Thanks!

EDIT:

  • I have manually set the affinity of the process in Task Manager to a single core on the dual CPU.
  • Sometimes I can catch it utilizing 51% or 52% of the CPU.

听起来你有一个双核CPU,你的应用程序是单线程的。

Sounds like you have a dual core cpu. Setting the processor affinity won't do anything to speed up your program. Also the 51/52% you see are other processes running on the other core at 1-2% PLUS your program running on the first core at full speed.

If you want to attempt to make your program use both cores, try looking into PLINQ in the Parallel Extensions library.

Parallel Extensions Library

Plinq Article

If your application executes on only one thread and you happen to have a dual core processor only one of the cores will be used, thus you use 50% of the available processor power.

If you have the possiblity to divide the work into logical pieces and spawn threads dealing with those pieces you may use both cores.

You have a processor with two cores. Your application only has one thread, which can only run on one core. It utilizes this core to 100%. If you want to use the other core as well, you'll have to use more threads.

As others have said, your app is running on one core of your dual (2) core CPU. When you see 50% in Task Manager, it means that the core that is running your app, which is one-half of your CPU's computing power, is running at 100%.

Writing software to make use of multi-core CPUs is an art unto itself. See this article for discussion. As @Alex Moore says, if you see 51% or 52%, it probably means that the other core is doing something at 1%-2%.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM