Weird performance behaviour
Oleg Endo
oleg.endo@t-online.de
Fri Aug 11 17:24:00 GMT 2017
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
More information about the Gcc-help
mailing list