CPU loader app
I wanted to test how my PC behaves under heavy CPU load. Googgled to find some apps that could do that, but after a minute decided to write my own ;)
This is how CPULoader.exe was born. Usage is to load the app in command prompt. After the "CPULoader.exe" you can specify how many threads you prefer to start. Program defaults to 2.
f.ex, if you have the exe on your Desktop:
C:\Users\your_user_name>\Desktop>CPULoader.exe 3
Here is the source (C#):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace CPULoader
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("This program starts a number of threads (default is 2) and performs sqare root operations in an ifinite loop on random numbers to load CPU's to test it under heavy load.");
Console.WriteLine("\nProgram was created by Vaidas Sirtautas");
Console.WriteLine("\n\tUsage: CPULoader.exe <number of threads to start>");
int count = 2;
if (args.Length == 1)
try
{
count = Int32.Parse(args[0]);
}
catch (Exception e)
{
Console.WriteLine("\n\n\tException occured. Probably not a number supplied. Defaulting to 2 threads\nException message: " + e.Message);
}
Console.WriteLine("Starting {0} threads to load the cpu(s)...", count);
Thread[] threads = new Thread[count];
for (int i = 0; i < count; i++)
{
threads[i] = new Thread(doWork);
threads[i].Start();
Console.Write("\nStarted thread #{0}", i);
}
Console.WriteLine("\n\tdone! Press any key to terminate all the threads");
ConsoleKeyInfo keypress = Console.ReadKey();
for (int i = 0; i < count; i++)
{
Console.Write("\nTerminating thread #{0}", i);
threads[i].Abort();
}
Console.WriteLine("\n");
return;
}
static void doWork()
{
Random random = new Random();
double a = 0.0;
while (true)
for (int j = 0; j < Int32.MaxValue; j++)
a = Math.Sqrt((Double)random.Next(Int32.MaxValue));
}
}
}
You can also download the app from here: http://uploading.com/files/67ea5m27/CPULoader.exe/
or here: http://88.223.59.161:88/CPULoader.exe
© Vaidas Sirtautas.RSS