Well it looks like NTL is nowhere near as fast as GMP. I used this code (mersenneNTL.cpp)
Code:
#include <NTL/ZZ.h>
NTL_CLIENT
int main(int argc, char *argv[]) {
char *endptr;
unsigned long int a = strtoul(argv[1],&endptr,10);
ZZ b = power2_ZZ(a) - 1;
cout << b;
return 0;
}
and compiled and ran it like this
Code:
$ g++ -o mersenneNTL mersenneNTL.cpp -lntl
$ time ./mersenneNTL 43112609 > M46
to compute the 46th Mersenne prime (2^43112609 - 1). After 21 minutes (with my cpu heating up to 140F) and still not finished I finally had to kill it. With GMP it takes about 6 seconds to finish. I tried removing the last digit (so that it'd compute 2^4311260 - 1), and the NTL version did finish in about 17 seconds, whereas the GMP version did it in less than a second.
I think the bottleneck with NTL might be the cout statement. GMP has a specialized printf function called gmp_printf that recognizes the large integer type, but for NTL I couldn't find an equivalent so I stuck with cout.