Search code examples
performancefortranoperation

using power operation "**" and multiple multiplications in Fortran


Which one do you think if the faster operation in Fortran?

x**2   VS   x*x
x**3   VS   x*x*x
x**4   VS   x*x*x*x
x**5   VS   x*x*x*x*x

Solution

  • My advice: write your code for readability. This will payoff in getting your programs correct and in future maintenance. Modern optimizing compilers will very likely implement these kind of optimizations for you ... or even cleverer ones that you might not think of. What of X**4 = (x*x) * (x*x) ? With (x*x) evaluated once and stored?