CPU Intensive Calculation Examples?
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.)
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.
...
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.
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.