Introduction
There are lots of utilities out there capable of creating a high CPU load to stress-test your processor(s). On Microsoft Windows, you can even use the on-board calculator.exe
, enter a large number like 999999999
, and press n!
several times to make your CPU(s) work overtime.
But what’s in a solution if you didn’t create it yourself?
The mission
Your mission – if you choose to accept it – is to create the smallest CPU stress-test tool on the planet.
Must…
- must produce 100% CPU load until aborted
- must take a numeric input, representing the number seconds the stress-test should run
- must allow user interaction (keypress, closing terminal window, or something like that) which should enable a user to abort the stress-test and/or quit the program
- must target Microsoft Windows, Mac OSx, and/or Linux.
(Even a hamster could stress a Comodore64… therefore, you must target a current operating system.)
Must not…
- must not use 3rd-party programs or tools which replace expected functionality.
(Proposing shortcuts in the likes ofsystem('cpuStressThing.exe')
disqualifies your proposal.)
May…
- may use any approach/algorithm/functionality to produce expected 100% CPU load
- may use any programming or scripting language
(as long as it allows practical verification of its functionality by running it)
Winning Condition
Present the smallest sourcecode possible. The winner is the one presenting the most minimal (in size) sourcecode that complies to the above “must” and “must not” conditions. Now, make that baby burn…
EDIT
Since the question came up in the comment area… you only need to target 1 CPU core. I'm definitely not expecting you to produce a multi-core solution. After all, this should be fun – not work.