2

It's mostly all in the title. How do you report the runtime of a C++ program that has intensive calculations at compile-time?

If I have a program that, when I use the bash time command on it, appears to run in .5 seconds, but the COMPILE TIME CALCULATIONS take over 10 minutes, can I honestly say my program runs in .5 seconds?

Christophe
  • 81,699

2 Answers2

8

You don't. Run-time is not compile-time, and nobody except the developer cares in the least how long compilation took.

(But also what Peter said: if your system really works like this, then something is very wrong to begin with.)

Kilian Foth
  • 110,899
5

The Sieve of Eratosthenes calculates all prime numbers up to any given limit. If you're calculating primes at compile time you're simply shifting what would have been a run time speed cost to a space cost. Yes your program runs faster when ran for primes "under a certain limit" but the bigger that limit the bigger your program.

It's called the space time tradeoff. It's why algorithms aren't only rated in big O for speed but also space.

In terms of speed the Sieve is O(n log log n). Space is O(n).

Your pre-calculated Sieve has speed at O(1) and space is the same. Except the pre-calculation invents a new big O category to consider: distribution size. Where the classic Sieve algorithm's distribution size is O(1) your pre-calculated Sieve distribution size is O(n).

Congrats. It's a different way to tradeoff. One that requires maintaining and distributing n binaries. Enjoy.

candied_orange
  • 119,268