Computationally Calculate Core Count Almost all operating systems allow you to run multiple programs at the same time. If your system does not have enough processors to run all the programs you want to run, it starts to give each program just a tiny slice of time on the processor it runs on. This is normally not noticeable but can lead to strange artefacts that you might not expect.

Your task is to write a program that tries to find out how many cores your computer has without asking the operating system. This is a popularity contest, the most upvoted solution wins. Here are the constraints:


While you cannot expect that your submission is the only thing that runs, you may expect that all other programs on the system are idling and wake up only sporadically.
You may not ask the operating system how many cores your computer has. Neither may you look up this number from any configuration file or similar. You may also not invoke a utility that provides you with that information.
For the sake of this challenge, the number of cores your computer has is the number of processes your computer can run at the same time. For instance, if you have an Intel processor with 2 cores and hyper threading, that would count as 4 cores.
Your solution needs not to be precise. It should not be terribly wrong all the time though.
C++11
Simply compares single core performance with threaded performance until there is not a linear speedup anymore. It's important that you do not have any other CPU intensive process running at the same time.
Compile with -O2 -m64 -march=native -std=c++11. You might have to pass -lpthread.
#include &lt;chrono&gt;
#include &lt;cstdint&gt;
#include &lt;future&gt;
#include &lt;iostream&gt;
#include &lt;vector&gt;

double f() {
    double cnt = 0;
    std::chrono::time_point&lt;std::chrono::high_resolution_clock&gt; start, end;
    start = std::chrono::system_clock::now();

    while (true) {
        end = std::chrono::system_clock::now();
        std::chrono::duration&lt;double&gt; elapsed = end - start;
        if (elapsed.count() &gt; 1.) break;
        cnt++;
    }

    return cnt;
}

int main(int argc, char** argv) {
    double one_core = f();

    int n = 1;
    while (true) {
        std::vector&lt;std::future&lt;double&gt;&gt; futures;
        for (int i = 0; i &lt; n; ++i) {
            futures.push_back(std::async(std::launch::async, f));
        }

        double tot = 0;
        for (int i = 0; i &lt; n; ++i) tot += futures[i].get();
        if (int(tot / one_core + 0.5) != n) {
            std::cout &lt;&lt; n - 1 &lt;&lt; &quot; core(s)\n&quot;;
            return 0;
        }

        ++n;
    }
}