Executive summary: sqrt from the glibc-2.0.6-9.alpha.rpm appears to be
over 10 times faster than sqrt in glibc-2.0.7-19.alpha.rpm.
Details:
I have two machines on which I can run tests. Both are 533Mhz EV56
systems. The primary hardware difference is that one is an LX164 and
the other is an SX164. I don't think that's relevant to the problem,
but 'full disclosure' is always a good idea. /proc/cpuinfo is
attached at the end of this note.
Machine 1 (LX164) has RH5.1 and glibc-2.0.7-19 installed from the updates
rpm.
Machine 2 (SX164) has RH5.0 and glibc-2.0.6-9 installed from an rpm (source
unknown, possibly from updates, but it no longer exists at ftp.redhat.com).
A very simple code that times a loop of 1million calls to sqrt is attached.
I compiled it with -static on both platforms and then ran the resulting
executable on both platforms. On both platforms, the glib-2.0.6-9 code
runs nearly eleven times faster. For example:
[johns@paranal junk]$ sqrtloop.static.06
1000000 sqrts in 0.1952 sec, 5.12295e+06 per sec
[johns@paranal junk]$ sqrtloop.static.07
1000000 sqrts in 2.13549 sec, 468277 per sec
[johns@paranal junk]$
Compiling without -static gives consistent results. I..e., the machine
with the 2.0.6 dynamic library is faster by about a factor of 10,
regardless of where the compilation was performed).
So the question is:
Why is the 2.0.7 sqrt so much slower than the 2.0.6??
I thought I'd take a look at glibc-2.0.6-9.src.rpm to try to find out.
I can't find it anywhere! (HotBot, ftp.redhat.com). Does anybody have
an archived copy?
Thanks for your help,
John Salmon
Appendix 1: C source code to sqrtloop.c
[johns@paranal junk]$ cat sqrtloop.c
---------------------------
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define NTIMES 1000000
int main(int argc, char **argv){
int i = NTIMES;
double x = 0.7;
clock_t tstart, tend;
double seconds;
tstart = clock();
while(--i){
x = sqrt(x) + 0.5;
}
tend = clock();
seconds = ((double)(tend-tstart))/CLOCKS_PER_SEC;
printf("%d sqrts in %g sec, %g per sec\n",
NTIMES, seconds, NTIMES/seconds);
return 0;
}
-----------------------------
Appendix 2: /proc/cpuinfo details
Machine 1 (glibc-2.0.7-19.rpm)
[johns@paranal junk]$ cat /proc/cpuinfo
cpu : Alpha
cpu model : EV56
cpu variation : 0
cpu revision : 0
cpu serial number : Linux_is_Great!
system type : EB164
system variation : LX164
system revision : 0
system serial number : MILO-0000
cycle frequency [Hz] : 0
timer frequency [Hz] : 1024.00
page size [bytes] : 8192
phys. address bits : 40
max. addr. space # : 127
BogoMIPS : 530.57
kernel unaligned acc : 0 (pc=0,va=0)
user unaligned acc : 134 (pc=155556b77a0,va=11ffff8c8)
platform string : N/A
Machine 2 (glibc-2.0.6-9.rpm):
[johns@avalon2 libm]$ cat /proc/cpuinfo
cpu : Alpha
cpu model : EV56
cpu variation : 0
cpu revision : 0
cpu serial number : Linux_is_Great!
system type : EB164
system variation : SX164
system revision : 0
system serial number : MILO-0000
cycle frequency [Hz] : 0
timer frequency [Hz] : 1024.00
page size [bytes] : 8192
phys. address bits : 40
max. addr. space # : 127
BogoMIPS : 528.48
kernel unaligned acc : 0 (pc=0,va=0)
user unaligned acc : 220 (pc=155556dc6b0,va=11ffffc40)
platform string : N/A