// test performance.cpp : Defines the entry point for the console application.
//
#include
#include
#include
#include
#include
#include
#include
typedef boost::safe_numerics::safe safe_type;
namespace boost {
namespace multiprecision {
template
typename enable_if_c::value, Integer&>::type
multiply(Integer& result, const I2& a, const I2& b){
return result = static_cast(a) * static_cast(b);
}
template
typename enable_if_c::value, bool>::type
bit_test(const Integer& val, unsigned index){
Integer mask = 1;
if (index >= sizeof(Integer) * CHAR_BIT)
return 0;
if (index)
mask <<= index;
return val & mask ? true : false;
}
template
typename enable_if_c::value, I2>::type
integer_modulus(const I1& x, I2 val){
return x % val;
}
namespace detail {
template struct double_integer;
template <>
struct double_integer{
using type = boost::safe_numerics::safe;
};
}
template
typename enable_if_c::value, I1>::type
powm(const I1& a, I2 b, I3 c){
typedef typename detail::double_integer::type double_type;
I1 x(1), y(a);
double_type result;
while (b > 0){
if (b & 1){
multiply(result, x, y);
x = integer_modulus(result, c);
}
multiply(result, y, y);
y = integer_modulus(result, c);
b >>= 1;
}
return x % c;
}
template
inline unsigned
lsb(const boost::safe_numerics::safe& x){
return lsb(static_cast(x));
}
} }
#include
template
class stopwatch
{
const typename Clock::time_point m_start;
public:
stopwatch() :
m_start(Clock::now())
{}
typename Clock::duration elapsed() const {
return Clock::now() - m_start;
}
};
template
void test(const char * msg){
const stopwatch c;
unsigned count = 0;
for (T i = 3; i < 30000000; ++i)
if (boost::multiprecision::miller_rabin_test(i, 25)) ++count;
std::chrono::duration time = c.elapsed();
std::cout<< msg << ":\ntime = " << time.count();
std::cout << "\ncount = " << count << std::endl;
}
int main()
{
test("Testing type unsigned");
test>("Testing type safe");
return 0;
}