This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gfortran and power calculation


Hi,

I tried to calculate the relations:

a=b**1.5

and

a=sqrt(b)**3

they are the same in the mathematical point of view but the second version works 7 times faster. I tried it with various optimization levels without big difference.
I think that it is easy to optimize no the code level.


I'm not a member of the group so if you need more details write to me directly.

bellow is the piece of code I have used to check the problem

program aaaa
 integer, parameter:: N=10000000
 real*8 a(N)
 integer i
 real czas0,czas1 !time0, time1
 ! some initial values
 do i=1,N
  a(i)=real(i,8)*0.1
 enddo
 ! the first version
 call cpu_time(czas0)
 do i=1,N
  a(i)=a(i)**1.5
 enddo
 call cpu_time(czas1)
 print*,"pow 1.5",czas1-czas0
 ! the second version
 call cpu_time(czas0)
 do i=1,N
  a(i)=sqrt(a(i))**3
 enddo
 call cpu_time(czas1)
 print*,"sqrt/pow",czas1-czas0
end

See you



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]