Custom Sieve of Eratosthenes
Missing header

Include &lt;cstring&gt; to get a definition of std::memset (and add the missing namespace qualifier where you use it).

Unused headers

We're not using &lt;bitset&gt;, &lt;fstream&gt; or &lt;string&gt;.

Prefer C++ headers

Use &lt;cmath&gt; in preference to &lt;math.h&gt; for new code, to place the identifiers into the std namespace (the only identifier that needs updating where it's used is std::sqrt).

Non-standard headers

Instead of platform-specific headers, you can use Standard C++ &lt;chrono&gt; for timing the code:

#include &lt;chrono&gt;

int main()
{
    auto const starttime = std::chrono::high_resolution_clock::now();

    do_work();

    auto const endtime = std::chrono::high_resolution_clock::now();


    auto const time_in_ms =
        std::chrono::duration_cast&lt;std::chrono::milliseconds&gt;(endtime - starttime);

    std::cout &lt;&lt; "Time taken:  "
              &lt;&lt; time_in_ms.count() &lt;&lt; " ms\n";
}


Unused variable

We never use totalMemset - leaving it in makes your code look like it's not really ready for review.

Use unsigned types

Most of the numbers used in this program are necessarily non-negative.  Prefer unsigned types to make this more apparent (and to give you twice as much range of values).

Prefer constants to preprocessor macros

This is better, as it's strongly typed, and won't be expanded in the wrong context:

const std::size_t RUNS = 10000;


Use * for arithmetic, not &lt;&lt;

An optimising compiler should generate the same code for

int j = (i &lt;&lt; 1)*i + (i &lt;&lt; 2) + (i &lt;&lt; 1) + 3;


as for

int j = 2*i*i + 4*i + 2*i + 3;


The latter more clearly conveys your intent (and you could collect 4*i + 2*i to simply 6*i).  Don't attempt to micro-optimize this!

Prefer range-based for

Instead of counting elements like this:

int count;
for (int i = 0; i&lt;R2; i++) if (primes[i] == 0) count++;


Here's a simpler form:

std::size_t count = 0;
for (auto n: primes)
    count += !n;