10

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 ?

Darqer
  • 2,847
  • 9
  • 45
  • 65

13 Answers13

14

Calculate PI using all processors.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
6

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

Klaus Byskov Pedersen
  • 117,245
  • 29
  • 183
  • 222
4

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.

Alex J
  • 9,905
  • 6
  • 36
  • 46
  • 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
4

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. :)

GWLlosa
  • 23,995
  • 17
  • 79
  • 116
3

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

Tom Bushell
  • 5,865
  • 4
  • 45
  • 60
  • No it must be a custom solution. – Darqer Jan 13 '11 at 23:06
  • 3
    @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
2

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

Program to find prime numbers

Community
  • 1
  • 1
Aim Kai
  • 2,934
  • 1
  • 22
  • 34
2

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

finnw
  • 47,861
  • 24
  • 143
  • 221
2

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.

ChristopheD
  • 112,638
  • 29
  • 165
  • 179
1

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) {
  i++;
}
Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
  • 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 07: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
1

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

marcelo-ferraz
  • 3,147
  • 4
  • 38
  • 55
1

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

Dave Swersky
  • 34,502
  • 9
  • 78
  • 118
1

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

void deathToAllRobots(int someMeaninglessValue) {
    deathToAllRobots(someMeaninglessValue+1);
}
JohnFx
  • 34,542
  • 18
  • 104
  • 162
0
int *x;
while(1)
{
     x = new int[10];
}
Ahmad Farid
  • 14,398
  • 45
  • 96
  • 136