#include <iostream>
#include <ctime>
#include <cstdint>
using std::cout;
using std::endl;
std::uint32_t rand_value;
std::uint32_t lcg()
{
const auto a = 22695477u;
const auto c = 1u;
rand_value = a * rand_value + c;
return rand_value;
}
enum func_method {log_or, mult};
template <typename test_type, func_method method>
void test_func()
{
const unsigned long end = 800'000'000;
unsigned int sum = 0;
std::uint32_t mask = 32767;
auto clock_begin = std::clock();
if (method == func_method::log_or)
for (unsigned long i = 0; i < end; ++i)
{
test_type a = lcg() & mask;
test_type b = lcg() & mask;
if (a == 0 || b == 0)
++sum;
}
else if (method == func_method::mult)
for (unsigned long i = 0; i < end; ++i)
{
test_type a = lcg() & mask;
test_type b = lcg() & mask;
if (a * b == 0)
++sum;
}
else
cout << "Invalid method" << endl;
auto clock_end = std::clock();
cout << "sum: " << sum << endl;
cout << "time: " << double(clock_end - clock_begin) / CLOCKS_PER_SEC << endl;
}
int main()
{
typedef int test_type;
rand_value = 1;
test_func<test_type, func_method::mult>();
rand_value = 1;
test_func<test_type, func_method::log_or>();
return 0;
}