Computationally Calculate Core Count
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;
    }
}