SQLSavant
SQLSavant

Reputation: 442

Process for eating up CPU usage

This may be an "out-there" question, but here goes:

I'm currently writing a bandaid script for an application to check multiple processes under the same name, such as chrome.exe using a PerformanceCounter in C#. Multiple instances of this process could possibly be running at the same time on the machine, so checking each one to see if it's above X% is needed. Unfortunately, this application does not have a test environment and no easy way to set one up.

So my question is, does anyone know of a tool or "mock" process that I can use to drive up the CPU usage so that I can test my script on? I'm basically wanting to create CPU usage. Are there such testing tools out there? Or is there a way to do this programmatically?

Upvotes: 1

Views: 761

Answers (2)

Clint
Clint

Reputation: 6220

for (int i = 0; i < 10; i++)
{
    ThreadPool.QueueUserWorkItem(new WaitCallback((a) =>
    {
        while (true) { }
    }));
}

while (true) { }

That will quite likely cause your CPU to jump up a fair bit given a thread will be going round and round non-stop without any break.

That gets up to about 85% utilisation on my machine.

Upvotes: 6

DasKr&#252;melmonster
DasKr&#252;melmonster

Reputation: 6060

You can do that online, using chrome. ==> http://www.fossiltoys.com/cpuload.html

Most realistic test ever!

Upvotes: 0

Related Questions