Take the 2-minute tour ×

I'm searching for code in c# that can kill computer performance (CPU performance, maybe cpu - memory link performance too) as much as it is possible (it will run on 4 core box so I'm going to create 4 threads and run it simultaneously).

Should it work on int / double / numeric data type / should it have some crazy data structures (but it should not take too much memory) .

Do you have any suggestions ?

share|improve this question

closed as not constructive by casperOne Aug 16 '12 at 16:48


while(true){} ? –  Klaus Byskov Pedersen Jan 13 '11 at 14:03
@Klaus doesn't consume much memory :) –  marcog Jan 13 '11 at 14:05
@Klaus - would also probably only occupy a single processor. –  Oded Jan 13 '11 at 14:06
Just for curiosity... why ? –  digEmAll Jan 13 '11 at 14:22
Sometimes I have to test computers remotely and I want to check what happen which them, when they are heavily overwhelmed. –  Darqer Jan 13 '11 at 14:26

13 Answers 13

up vote 14 down vote accepted

Calculate PI using all processors.

share|improve this answer
It worked on Star Trek, it can work for you. –  RQDQ Jan 13 '11 at 14:07
@RQDQ - I must have missed that episode. –  Oded Jan 13 '11 at 14:07
Probably this one: youtube.com/watch?v=H20cKjz-bjw –  Uwe Keim Jan 13 '11 at 17:19

You could use parallel Linq to generate a Mandelbrot (Jon Skeet has the code readily available).

share|improve this answer

Have a program that writes copies of its executable to the drive multiple times for each thread. Have each of these copies of the program then triggered by the program. :)

share|improve this answer
hehe, how to stop it ? :) –  Darqer Jan 13 '11 at 15:52
That's a different question altogether. :P –  GWLlosa Jan 13 '11 at 15:54
It stops when the computer does :) –  Poindexter Jan 13 '11 at 17:30
Searching for more controlled way :P –  Darqer Jan 13 '11 at 23:05
You could add code that counts existing instances of the program and throttles itself at some preset limit, I suppose. –  GWLlosa Jan 13 '11 at 23:09

If you want to kill a machine's performance, try hitting the disk, because IO interrupts tend to affect everything even on a good CPU scheduler. Something like enumerating a directory of many little files, or writing a lot of big files to disk would do the trick.

share|improve this answer
Great idea enumerating like enumerating Windows directory, any more suggestion with HDD ? –  Darqer Jan 13 '11 at 14:44
You can combine any other suggestion here and just write the output to a file. Make sure you flush your buffers between every write so it actually goes to disk rather than just staying in memory. –  Alex J Jan 13 '11 at 14:54
There are some application that can kill system performance by disks IO you simply run it and everything stops, but I think that simple read write might have too low priority –  Darqer Jan 13 '11 at 23:05
+1 Great answer, people tend to forget this aspect when considering overall system performance. –  Chris O Jan 29 '11 at 20:08

Why re-invent the wheel? Use existing Load Testing software.

share|improve this answer
No it must be a custom solution. –  Darqer Jan 13 '11 at 23:06
@Darqer- "It must be custom?" Why put that kind of constraint on solving the problem? I thought you wanted to waste the computer's time, not yours. –  AShelly Jan 14 '11 at 17:49
I have to be able to control it (turn it on / off) through simple tcp / ip call :). Well and second it might be interesting to implement it on my own :) kind of programming fun :) –  Darqer Jan 14 '11 at 20:59

Calculate a long sequence of prime numbers. The following link contains code that can be modified to do this..

Program to find prime numbers

share|improve this answer

Call Bitmap.GetPixel, in a loop, in an image processing application.

share|improve this answer

I would say: a naieve (brute force) travelling salesman implementation:

(from wikipedia):

The Travelling Salesman Problem (TSP) is an NP-hard problem in combinatorial optimization studied in operations research and theoretical computer science. Given a list of cities and their pairwise distances, the task is to find a shortest possible tour that visits each city exactly once.

share|improve this answer

Brute force solving of N Queens (see wikipedia) for for example 64 queens.

Because a simple loop like this can be optimized away (sometimes only after a few minutes already running):

while(true) {
share|improve this answer
Declare i as volatile to prevent the optimization –  finnw Jan 15 '11 at 19:22
@finnw: Even if i is a global field and i is volatile, it's still possible that the latest JVM (or a future JVM) detects that this piece of code is only run once and therefor i can be made a local variable and therefor the volatile nature becomes irrelevant. –  Geoffrey De Smet Jan 16 '11 at 7:20
this is a .NET question, but I think you are wrong about Java also, because the VM cannot know that another class will not be loaded later that will read i by reflection. –  finnw Jan 16 '11 at 12:58

You can, as well, resolve a very long encrypted message, encrypted by a key such as 2048 bits. That's a killer.

share|improve this answer

An open-source, multithreaded 3D modeling program rendering an extremely complex lighted scene will pound the strongest system into submission.

share|improve this answer

Okay, how about some infinite recursion in the spirit of StackOverflow?

void deathToAllRobots(int someMeaninglessValue) {
share|improve this answer
int *x;
     x = new int[10];
share|improve this answer
Doesn't look much like C# –  Roger Perkins Jan 13 '11 at 14:08
Compilers will probably optimise this one too. –  marcog Jan 13 '11 at 14:13
