Skuta
Skuta

Reputation: 5860

How to maximize power used by my application in C#?

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%?

Upvotes: 2

Views: 929

Answers (4)

zendar
zendar

Reputation: 13572

Check this:

  1. Do you read from disk while calculating? If so, try to read data in memory before calculations.
  2. Do you write results to disk or console while calculating? If so, try to postpone writing until calculation is over and then do writing.
  3. If you have multicore processor, try to create multithreaded algorithm if possible.

Upvotes: 2

ScottS
ScottS

Reputation: 8553

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.

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

Upvotes: 1

Erik Funkenbusch
Erik Funkenbusch

Reputation: 93444

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.

Upvotes: 2

Reed Copsey
Reed Copsey

Reputation: 564631

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.

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.

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.

Upvotes: 7

Related Questions