I recently started experimenting with autocompile in Maple.

I must say that I am bit surprised by the difference in performance for different loops and procedures

depending of what type of notation you use. I have below presented 3 procedures that uses slightly

difference notation. We can see that the first procedure (iterating over list elements) is extremely slow in Maple.

The second procedure is faster but the third procedure (compiled, converted to C ) is fastest.

I assume that the goal for everyone is fast numerical computation so I ask myself the question:

Why are not all loops by default converted to C ?

 


restart:

X := proc (n) local i, s;

s[0] := 0.0:  for i to n do s[i] := s[i-1]+100.0 end do:

return s[n] ;

end proc:

 



XX := proc (n) local i, s;

s := 0.0:   for i to n do s := s+100.0 end do:

return s ;

end proc:

  


XXX := proc (n) local i, s;   option autocompile:

s := 0.0:  for i to n do s := s+100.0 end do:

return s ;

end proc:

 



time(X(1000000));

time(XX(1000000));

time(XXX(1000000));

 



                                    7.675
                                    2.558
                                    0.218
 


Please Wait...