See what's going on with flipcode!

This section of the archives stores flipcode's complete Developer Toolbox collection, featuring a variety of mini-articles and source code contributions from our readers.


  How To Arrange Time To Take A Coffee Break
  Submitted by

Are your recompiles too fast?

Perhaps you've read Large Scale C++ Software Design and refactored your code only to notice that you no longer have time to take coffee breaks. Sadly you realize that the 30 minute recompiles are a thing of the past.

Wait, there is hope. Just use DELAY(N)!

DELAY(N) is a preprocessor macro, which essentially expands to nothing while wasting a lot of preprocessing time. The time complexity of DELAY(N) is O(pow(2,N)). This means that when you increase the argument to DELAY(N) by one, the time it takes for the preprocessor to expand it roughly doubles.

For example, on the 800MHz PIII I use at the office, it takes roughly 4 seconds to preprocess DELAY(15) using MSVC++. Since the maximum argument to DELAY(N) is 50, I can use it to generate delays of pow(2,50-15)*4 seconds. This does not impress you? Well, pow(2,50-15)*4 seconds is roughly 4000 years!

So, the next time I want to take a 30 minute coffee break, while recompiling, I just say:


The DELAY() macro implementation is available at Boost. You need to take the latest sources from the CVS. Just follow the instructions for downloading. To take a peek at the source immediately, click here.

Editor's note: LOL

The zip file viewer built into the Developer Toolbox made use of the zlib library, as well as the zlibdll source additions.


Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.