octave, matlab, maxima



~~~

Why is the execution time of Maxima for-loop statements different 
than the equivalent Fortran do-loop execution time.

For example the execution time of the time the nested Maxima for-loop is: 

(%i23) for j:1 thru 1000 do (for k:1 thru 1000 do return);
Evaluation took 3.9800 seconds (3.9800 elapsed)
(%o23) done

and for the the equivalent Fortran do-loop: 

program test
do j=1,1000
 do k=1,1000
 end do
end do
end program test 

which we compile and call the executable from Maxima:

(%i27) system("C:\user_fortran\test_do_timer.exe")
Evaluation took 0.0800 seconds (0.0800 elapsed)
(%o27) 0

the uncompiled Maxima loop is factor of 4.11/.08 or 51 times slower than Fortran.

For the compiled equivalent Maxima for-loop function:

(%i32) f(n):=for j:1 thru n do (for k:1 thru n do return);
(%i33) f(1000); /* call for n=1000 */
Evaluation took 3.9200 seconds (3.9200 elapsed)
(%o33) done     /* the function takes as long as the one line Maxima statement loop */

(%i34) compile(f);
Warning-> return is an undefined global variable.Compiling C:/DOCUME~1/erom/LOCALS~1/Temp/gazonk_340_0.lsp.
End of Pass 1.  End of Pass 2.  
OPTIMIZE levels: Safety=2, Space=3, Speed=3
Finished compiling C:/DOCUME~1/erom/LOCALS~1/Temp/gazonk_340_0.lsp.
(%o34) [f]

the time for the compiled Maxima loop:

(%i35) f(1000);
Evaluation took 0.8000 seconds (0.8000 elapsed)
(%o35) done

compiled Maxima is still a factor of 10 slower than fortran.

One would think there is no need for symbolic mathematics in loop statements alone. 
where is the time factor of 10 consumed.


Ed

~~~