views:

180

answers:

5

I need a few easily implementable single cpu and memory intensive calculations that I can write in java for a test thread scheduler.

They should be slightly time consuming, but more importantly resource consuming.

Any ideas?

+2  A: 

Multiply two matrices. The matrices should be huge and stored on the disk.

String search. Or, index a huge document (detect and count the occurrence of each word or strings of alphabets) For example, you can index all of the identifiers in the source code of a large software project.

Calculate pi.

Rotate a 2D matrix, or an image.

Compress some huge files.

...

rwong
Or just append to StringBuilder in a forloop over N seconds.
jojaba
+2  A: 

Ok this is not Java, but this is based on Dhrystone benchmark algorithm found here. These implementations of the algorithm might give you an idea on how is it done. The link here contains sources to C/C++ and Assembler to obtain the benchmarks.

tommieb75
+3  A: 

A few easy examples of CPU-intensive tasks:

  • searching for prime numbers (involves lots of BigInteger divisions)
  • calculating large factorials e.g. 2000! ((involves lots of BigInteger multiplications)
  • many Math.tan() calculations (this is interesting because Math.tan is native, so you're using two call stacks: one for Java calls, the other for C calls.)
dogbane
A: 
  1. Official RSA Challenge
  2. Unofficial RSA Challenge - Grab some ciphertext that you want to read in plaintext. Let the computer at it. If u use a randomized algorithm, there is a small but non-zero chance that u will succeed.
emory
+1  A: 

The CPU soak test for the PDP-11 was tan(atan(tan(atan(...))) etc. Works the FPU pretty hard and also the stack and registers.

EJP