Time a function: Difference between revisions

Added solution for Action!
m (→‎{{header|Phix}}: added with js, changed "+= i" to "+= odd(i)" to make it 32/64 bit compatible, and removed the requires(64))
(Added solution for Action!)
Line 163:
; (160,001,648 bytes allocated).
(NIL)</pre>
 
=={{header|Action!}}==
<lang Action!>BYTE RTCLOK1=$13
BYTE RTCLOK2=$14
BYTE PALNTSC=$D014
 
PROC Count(CARD max)
CARD i
 
FOR i=1 TO max DO OD
RETURN
 
CARD FUNC GetFrame()
CARD res
BYTE lsb=res,msb=res+1
 
lsb=RTCLOK2
msb=RTCLOK1
RETURN (res)
 
CARD FUNC FramesToMs(CARD frames)
CARD res
 
IF PALNTSC=15 THEN
res=frames*60
ELSE
res=frames*50
FI
RETURN (res)
 
PROC Main()
CARD ARRAY c=[1000 2000 5000 10000 20000 50000]
CARD beg,end,diff,diffMs
BYTE i
 
FOR i=0 TO 5
DO
PrintF("Count to %U takes ",c(i))
beg=GetFrame()
Count(c(i))
end=GetFrame()
diff=end-beg
diffMs=FramesToMs(diff)
PrintF("%U ms%E",diffMs)
OD
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Time_a_function.png Screenshot from Atari 8-bit computer]
<pre>
Count to 1000 takes 50 ms
Count to 2000 takes 100 ms
Count to 5000 takes 300 ms
Count to 10000 takes 600 ms
Count to 20000 takes 1150 ms
Count to 50000 takes 3000 ms
</pre>
 
=={{header|Ada}}==
Anonymous user