Poor performance with glibc exp() function on RHEL6 and RHEL7
Issue
Calls to glibc exp() function in applications compiled in 64bits have poor performance compared to 32bits.
Here is an example code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define SIZE (10000)
int main(int argc,char**argv)
{
int count, i;
volatile double b, x;
if (argc<3) { printf("error\n"); return 1; }
count = atoi(argv[1]);
b = atof(argv[2]);
for (i=0;i<count;i++) {
x = exp(b);
}
printf("(count=%d) e^%.27f = %.27f\n",count,b,x);
return 0;
}
And here are the performances between 32bits and 64bits binaries:
$ gcc -m32 exptest.c -lm -o exptest -Wall -ggdb
$ file exptest
exptest: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
$ time ./exptest 100000 -0.000000000000000277555756156
(count=100000) e^-0.000000000000000277555756156 = 0.999999999999999777955395075
real 0m0.015s
user 0m0.011s
sys 0m0.003s
$ gcc exptest.c -lm -o exptest -Wall -ggdb
$ file exptest
exptest: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
$ time ./exptest 100000 -0.000000000000000277555756156
(count=100000) e^-0.000000000000000277555756156 = 0.999999999999999777955395075
real 0m10.318s
user 0m10.294s
sys 0m0.002s
Environment
- Red Hat Enterprise Linux (RHEL) 6 and 7
- glibc
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.