cpusimulate

How do I simulate 100% CPU usage?


To simulate 100% CPU usage, I placed an infinite while loop in my code ( while (true) { } ) . This seemed to spike the CPU usage up to 30% (ordinarily it is 2% for the same program that I run without the while loop). Why does it not go above 30%? This is a dual core Intel i7 processor. The app is a simple console app running c# code on .net 4.0

 private static void SimulateCPUSpike()
 { 
       while(true) { }
 }

Solution

  • CPU usage is a percentage of all CPU cores.
    If your code is only running a single thread, it cannot occupy more than one core.

    You need to make a separate thread for each core. (Environment.ProcessorCount)