如何在C#中最大化我的应用程序使用的功率?

时间:2023-01-18 18:04:02

As I've created the application that is hard on calculations -> lots of work to do, not very complex calculations -> it takes too long to work it out and the process is only at 45% of the CPU. Can I maximize it somehow?: to go to 90%?

因为我已经创建了很难进行计算的应用程序 - >要做很多工作,而不是非常复杂的计算 - >它需要很长时间才能完成,而且过程只占CPU的45%。我可以以某种方式最大化它吗?:达到90%?

4 个解决方案

#1


If you have a dual core machine (which I'm guessing you do), the most you could hope to get in a single thread would be 50% CPU usage.

如果你有一个双核机器(我猜你这么做),你希望在一个线程中获得的最多就是50%的CPU使用率。

To get 90% CPU usage, you will most likely need to thread your calculations. This may be very simple, or very difficult, depending on the nature of the algorithm you want to thread.

要获得90%的CPU使用率,您很可能需要对计算进行处理。这可能非常简单,也可能非常困难,具体取决于您要线程化的算法的性质。

If you can break up your working set into multiple groups, I would recommend considering using the ThreadPool, or potentially even the Task Parallel Library, depending on your timing for release.

如果您可以将工作集拆分为多个组,我建议您考虑使用ThreadPool,甚至可能考虑使用任务并行库,具体取决于您的发布时间。

#2


More than likely you have a dual core CPU, and if your app is single threaded, the maximum CPU it will use is 50% (all of one core). In order to get better use, you need to utilize multiple threads, but that also means figuring out some way to break your calculations into pieces so that they can be worked on by more than one core.

您很可能拥有双核CPU,如果您的应用程序是单线程的,它将使用的最大CPU为50%(所有一个核心)。为了更好地使用,您需要使用多个线程,但这也意味着找出一些方法将计算分解为多个部分,以便它们可以由多个核心处理。

#3


Check this:

  1. Do you read from disk while calculating? If so, try to read data in memory before calculations.
  2. 你在计算时读取磁盘吗?如果是这样,请在计算之前尝试读取内存中的数据。

  3. Do you write results to disk or console while calculating? If so, try to postpone writing until calculation is over and then do writing.
  4. 在计算时是否将结果写入磁盘或控制台?如果是这样,请尝试推迟写入,直到计算结束,然后再写。

  5. If you have multicore processor, try to create multithreaded algorithm if possible.
  6. 如果您有多核处理器,请尽可能尝试创建多线程算法。

#4


If you just have a simple loop doing the calculations, then most likely your computer has two cores/processors. A single threaded application will at best use 50% of the CPU.

如果你只是有一个简单的循环进行计算,那么很可能你的计算机有两个核心/处理器。单线程应用程序最多只能使用50%的CPU。

You need multiple threads to use the whole CPU on a multi-core machine.

您需要多个线程才能在多核计算机上使用整个CPU。

#1


If you have a dual core machine (which I'm guessing you do), the most you could hope to get in a single thread would be 50% CPU usage.

如果你有一个双核机器(我猜你这么做),你希望在一个线程中获得的最多就是50%的CPU使用率。

To get 90% CPU usage, you will most likely need to thread your calculations. This may be very simple, or very difficult, depending on the nature of the algorithm you want to thread.

要获得90%的CPU使用率,您很可能需要对计算进行处理。这可能非常简单,也可能非常困难,具体取决于您要线程化的算法的性质。

If you can break up your working set into multiple groups, I would recommend considering using the ThreadPool, or potentially even the Task Parallel Library, depending on your timing for release.

如果您可以将工作集拆分为多个组,我建议您考虑使用ThreadPool,甚至可能考虑使用任务并行库,具体取决于您的发布时间。

#2


More than likely you have a dual core CPU, and if your app is single threaded, the maximum CPU it will use is 50% (all of one core). In order to get better use, you need to utilize multiple threads, but that also means figuring out some way to break your calculations into pieces so that they can be worked on by more than one core.

您很可能拥有双核CPU,如果您的应用程序是单线程的,它将使用的最大CPU为50%(所有一个核心)。为了更好地使用,您需要使用多个线程,但这也意味着找出一些方法将计算分解为多个部分,以便它们可以由多个核心处理。

#3


Check this:

  1. Do you read from disk while calculating? If so, try to read data in memory before calculations.
  2. 你在计算时读取磁盘吗?如果是这样,请在计算之前尝试读取内存中的数据。

  3. Do you write results to disk or console while calculating? If so, try to postpone writing until calculation is over and then do writing.
  4. 在计算时是否将结果写入磁盘或控制台?如果是这样,请尝试推迟写入,直到计算结束,然后再写。

  5. If you have multicore processor, try to create multithreaded algorithm if possible.
  6. 如果您有多核处理器,请尽可能尝试创建多线程算法。

#4


If you just have a simple loop doing the calculations, then most likely your computer has two cores/processors. A single threaded application will at best use 50% of the CPU.

如果你只是有一个简单的循环进行计算,那么很可能你的计算机有两个核心/处理器。单线程应用程序最多只能使用50%的CPU。

You need multiple threads to use the whole CPU on a multi-core machine.

您需要多个线程才能在多核计算机上使用整个CPU。