2

I'm seeking a(very) short statement(in any language) that can make the CPU busy for like a second or a half. The statement should consume CPU cycles, not IO stuff.

khelll
  • 23,590
  • 15
  • 91
  • 109

2 Answers2

3

Psuedocode:

A = 2
StartTime = GetTime()
While (GetTime() - StartTime) < 1.0
  A = A * 2
graham.reeds
  • 16,230
  • 17
  • 74
  • 137
  • 3
    My flippant answer was going to be `exec Outlook.exe`. Then I realised he only wanted to keep the CPU busy for a couple of seconds not about 30! – graham.reeds Jul 14 '10 at 10:01
1

Using java BigIntegers, you could try and implement http://en.wikipedia.org/wiki/Ackermann_function.

That'll keep you going for a while.

Erwin Smout
  • 18,113
  • 4
  • 33
  • 52
  • 1
    +1 I thought of Ackermann, but even the tightest implementation is going to be more than "a (very) short statement". Mind you, I suppose asker also says "in any language", and I bet the J / APL implementation of Ackermann is about one third of a line... – AakashM Jul 14 '10 at 10:11