FULL PRODUCT VERSION :
A DESCRIPTION OF THE PROBLEM :
The Math.exp() function is extremely slow for some exponents.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the applied test case. Change the base from 500 to 800 and see that the code is 1000x slower.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The time should be roughly the same. It is the same when running a similar C program using the libm library.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.concurrent.TimeUnit;
public class MathExpTest {
private static final int BASE = 500; // change to 800 and 1000x slower
public static void main(String[] args){
for(int i=0;i<=10;i++) {
long start = System.nanoTime();
long total = 0;
for(int j=0;j<10000000;j++) {
total+=testExp(i+BASE);
}
long diff= TimeUnit.NANOSECONDS.toMicros(System.nanoTime()-start);
System.out.printf("time is %f\n",diff/10000000.0);
System.out.println("total is "+total);
}
}
static int testExp(int i) {
return (int) (Math.sqrt(Math.exp(i)));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
write our own exp function, which is slower in most cases
A DESCRIPTION OF THE PROBLEM :
The Math.exp() function is extremely slow for some exponents.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the applied test case. Change the base from 500 to 800 and see that the code is 1000x slower.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The time should be roughly the same. It is the same when running a similar C program using the libm library.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.concurrent.TimeUnit;
public class MathExpTest {
private static final int BASE = 500; // change to 800 and 1000x slower
public static void main(String[] args){
for(int i=0;i<=10;i++) {
long start = System.nanoTime();
long total = 0;
for(int j=0;j<10000000;j++) {
total+=testExp(i+BASE);
}
long diff= TimeUnit.NANOSECONDS.toMicros(System.nanoTime()-start);
System.out.printf("time is %f\n",diff/10000000.0);
System.out.println("total is "+total);
}
}
static int testExp(int i) {
return (int) (Math.sqrt(Math.exp(i)));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
write our own exp function, which is slower in most cases