[英]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. 我有几个C#控制台应用程序,基本上解析内存中的大量数据(LINQ)并将结果输出到文本文件。
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. 当我在调试模式下运行应用程序时,我永远不会使用超过50%的CPU使用率。 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). 它将解析/按摩数十万条记录,但只能快速运行X并利用50%的CPU(在任务管理器中查看)。
I would really like to use 100% of the CPU to make the processing go faster. 我真的想用100%的CPU来加快处理速度。
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. 我正在运行带有Service Pack 3的Windows XP Professional。我安装了带Service Pack 1的Visual Studio 2008 Professional。
Thanks! 谢谢!
EDIT: 编辑:
听起来你有一个双核CPU,你的应用程序是单线程的。
Sounds like you have a dual core cpu. 听起来你有一个双核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. 此外,您看到的51/52%是在另一个核心上运行的其他进程,以1-2%加速您的程序在第一个核心上全速运行。
If you want to attempt to make your program use both cores, try looking into PLINQ in the Parallel Extensions library. 如果您想尝试让程序使用两个内核,请尝试在Parallel Extensions库中查看PLINQ。
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. 如果您的应用程序仅在一个线程上执行,而您碰巧有双核处理器,则只使用其中一个核心,因此您使用50%的可用处理器能力。
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%. 它利用这个核心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. 正如其他人所说,您的应用程序运行在双核(2)核心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%. 当您在任务管理器中看到50%时,这意味着运行您的应用程序的核心,即CPU的计算能力的一半,正在以100%运行。
Writing software to make use of multi-core CPUs is an art unto itself. 编写软件以利用多核CPU本身就是一门艺术。 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%. 正如@Alex Moore所说,如果你看到51%或52%,这可能意味着另一个核心正在做1%-2%的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.