On Fri, 2017-08-11 at 18:01 +0100, Marcel Keller wrote: > Hi, > > I've noticed that the performance of mpn_addmul_1 from MPIR can > depend considerably on whether I link against libpthread, which > strikes me as very weird: > > $ g++ -O3 Time-addmul_1.cpp addmul_1.o -o a.out > > $ g++ -O3 Time-addmul_1.cpp addmul_1.o -o b.out -lpthread > > $ ./a.out > mpn_addmul_1: 0.506279 > > $ ./b.out > mpn_addmul_1: 0.682086 > > Disassembling the binaries shows that the mpn function in > Time-addmul_1.cpp is compiled exactly the same way. There is nothing else in the code, except the 2 calls to clock_gettime. So the time difference must come from there somehow. You can check its implementation: https://github.com/lattera/glibc/blob/master/sysdeps/unix/clock_gettime.c So if there is __pthread_clock_gettime, it will try to use that. __pthread_clock_gettime gets there by pulling in libpthread. Cheers, Oleg