CPU Intensive Calculation Examples?

MEURSAULT picture MEURSAULT · Sep 12, 2010 · Viewed 22.4k times · Source

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?

Answer

dogbane picture dogbane · Sep 12, 2010

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