How to maximize CPU usage

Vittorio Rosso 1 Reputation point
2021-01-22T19:13:01.087+00:00

I wrote some program that doind a longtime calculations.
When i open a task manager, i see that my exe uses only 2% of CPU.

How shoult i write my code in c# to obtain a maximum CPU time to speed up my calculation?

I try to start a several copies of my exe, but overal load was still about 5%,ive spotted that all exe eat about 0.5% cpu.
Looks like a system has some upper limit and divide time between my exe.
Is there any cpu thing in .net that try to save system from overload?
I try to find out where is a problem, in my code, in CLR, in windows or in somwhere else.

I downloaded a WinRAR archiver and start a build-in benchmark. While benchmarking it eat 90% of CPU time. So i am sure my windows is ok. Problem is in my code or in dotnet security featureas, if they presents.

No multithreading in code.
Windows server 2019

Developer technologies .NET .NET Runtime
Developer technologies C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2021-01-22T20:05:14.177+00:00

    You should be able to use the profiling tools in Visual Studio to monitor performance.

    https://learn.microsoft.com/en-us/visualstudio/profiling/?view=vs-2019

    Another option is to use Sysinternals Process Monitor and trace your program to see if if is making redundant file I/O or registry calls.

    https://learn.microsoft.com/en-us/visualstudio/profiling/?view=vs-2019

    How many cores does your server have? A single threaded app can only use 100% of one cpu. So if you have 2 cpu's your program will use 50%. 4 cores will show 25%, etc.

    In the Details tab in Task Manager, add a column for Page Faults Delta. See if it's doing something with memory (file cache).

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.