time luajit sincosEuler9.luaor the like at the prompt, and the time command will run the rest of the line and report back how much time it took. This will work wrong for us Windows programmers at the Dos box prompt, because our time command has a completely different meaning. I have therefore written a program in the Windows version of FreeBasic. The program is timer.bas and it looks like
dim a as single, b as single a=timer shell(command$) b=timer print (b-a);" seconds"I have compiled it to an executable called timer.exe for our use. We can just type
timer luajit sincosEuler9.luato find out how long the sincosEuler9.lua program took. On my computer, using LuaJIT 2.0.0-beta1, and running three times, it took 5.402344 seconds, 5.078857 seconds, and 5.137695 seconds, or so says timer. That is much speedier than the previous LuaJIT, and Mr. Mike Pall deserves everybody’s thanks. The LuaJIT link is http://luajit.org/. My program is sincosEuler9.lua and it looks like
-- This program uses Euler's algorithm to solve the simultaneous -- ordinary differential equations for the sine and cosine. The -- interval of integration is from zero to one. local s=0 -- sine starts at zero local c=1 -- cosine starts at one local n=1e9 -- 1e9 steps local h=1/n -- size of one step local sNew -- a temporary location local cNew -- another temporary location for j=1,n do sNew=s+c*h cNew=c-s*h s=sNew c=cNew end print( s,c )
Back in 1958, when I first programmed on a computer, the great language was Fortran. I have written a program in it, sincosEuler9.f, to do the same thing that the Lua program does. It looks like
double precision s,c,n,h,j,sNew,cNew n=1 000 000 000 h=1.0d0/n s=0 c=1 do 17 j=1,n sNew=s+c*h cNew=c-s*h s=sNew c=cNew 17 continue print *,s,c endHaving used MinGW Fortran, that is g77, to compile the source, I ran the binary three times, and got 6.770508 seconds, 6.580322 seconds, and 6.564697 seconds. I think that I used the appropriate command line modifiers for speed, -O3 and -fomit-frame-pointer, when I compiled, but Fortran seems to be slower than LuaJIT for this algorithm.
Come to think of it, here is timer.zip containing all these files, including the index.htm file the reader is now reading. All the files in the zip are in the public domain. Of course, FreeBasic is not in the public domain. Its license is GNU General Public License (GPL), GNU Library or Lesser General Public License (LGPL). Mr. Mike Pall is the owner of LuaJIT. His copyright notice says Copyright (C) 2005-2009 Mike Pall.
at dot
smtw2gh gmail com
Harold Kaplan’s programming.htm