Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,105 @@
TC EQU 8 ; number of counter registers
TSTART EQU 08h ; first register of timer counter
TEND EQU TSTART + TC - 1 ; end register of timer counter
; Note: The multi-byte value is stored in Big-endian
; Some timer reloads
_6H EQU 085h ; 6MHz
_6L EQU 0edh
_12H EQU 00bh ; 12MHz
_12L EQU 0dbh
_110592H EQU 01eh ; 11.0592MHz
_110592L EQU 0ffh
; How to calculate timer reload (e.g. for 11.0592MHz):
; Note: 1 machine cycle takes 12 oscillator periods
; 11.0592MHz / 12 * 0.0625 seconds = 57,600 cycles = e100h
; ffffh - e100h = NOT e100h = 1effh
; assuming a 11.0592MHz crystal
TIMERH EQU _110592H
TIMERL EQU _110592L
;; some timer macros (using timer0)
start_timer macro
setb tr0
endm
stop_timer macro
clr tr0
endm
reset_timer macro
mov tl0, #TIMERL
mov th0, #TIMERH
endm
increment_counter macro ;; increment counter (multi-byte increment)
push psw
push acc
push 0 ; r0
mov r0, #TEND+1
setb c
inc_reg:
dec r0
clr a
addc a, @r0
mov @r0, a
jnc inc_reg_ ; end prematurally if the higher bytes are unchanged
cjne r0, #TSTART, inc_reg
inc_reg_:
; if the carry is set here then the multi byte value has overflowed
pop 0
pop acc
pop psw
endm
ORG RESET
jmp init
ORG TIMER0
jmp timer_0
timer_0: ; interrupt every 6.25ms
stop_timer ; we only want to time the function
reset_timer
increment_counter
start_timer
reti
init:
mov sp, #TEND
setb ea ; enable interrupts
setb et0 ; enable timer0 interrupt
mov tmod, #01h ; timer0 16-bit mode
reset_timer
; reset timer counter registers
clr a
mov r0, #TSTART
clear:
mov @r0, a
inc r0
cjne r0, #TEND, clear
start_timer
call function ; the function to time
stop_timer
; at this point the registers from TSTART
; through TEND indicate the current time
; multiplying the 8/16/24/etc length value by 0.0625 (2^-4) gives
; the elapsed number of seconds
; e.g. if the three registers were 02a0f2h then the elapsed time is:
; 02a0f2h = 172,274 and 172,274 * 0.0625 = 10,767.125 seconds
;
; Or alternatively:
; (high byte) 02h = 2 and 2 * 2^(16-4) = 8192
; (mid byte) a0h = 160 and 160 * 2^(8-4) = 2560
; (low byte) f2h = 242 and 242 * 2^(0-4) = 15.125
; 8192 + 2560 + 15.125 = 10,767.125 seconds
jmp $
function:
; do whatever here
ret
END

View file

@ -0,0 +1,19 @@
' FB 1.05.0 Win64
Function sumToLimit(limit As UInteger) As UInteger
Dim sum As UInteger = 0
For i As UInteger = 1 To limit
sum += i
Next
Return sum
End Function
Dim As Double start = timer
Dim limit As UInteger = 100000000
Dim result As UInteger = sumToLimit(limit)
Dim ms As UInteger = Int(1000 * (timer - start) + 0.5)
Print "sumToLimit("; Str(limit); ") = "; result
Print "took "; ms; " milliseconds to calculate"
Print
Print "Press any key to quit"
Sleep

View file

@ -0,0 +1,5 @@
local(start = micros)
loop(100000) => {
'nothing is outout because no autocollect'
}
'time for 100,000 loop repititions: '+(micros - #start)+' microseconds'

View file

@ -0,0 +1,5 @@
on testFunc ()
repeat with i = 1 to 1000000
x = sqrt(log(i))
end repeat
end

View file

@ -0,0 +1,5 @@
ms = _system.milliseconds
testFunc()
ms = _system.milliseconds - ms
put "Execution time in ms:" && ms
-- "Execution time in ms: 983"

View file

@ -0,0 +1,14 @@
import times, os
proc doWork(x) =
var n = x
for i in 0..10000000:
n += i
echo n
template time(s: stmt): expr =
let t0 = cpuTime()
s
cpuTime() - t0
echo time(doWork(100))

View file

@ -0,0 +1,3 @@
atom t0 = time()
some_procedure()
printf(1,"%3.2fs.\n",time()-t0)

View file

@ -0,0 +1,7 @@
beginTime = TimeList()[13]
for n = 1 to 10000000
n = n + 1
next
endTime = TimeList()[13]
elapsedTime = endTime - beginTime
see "Elapsed time = " + elapsedTime + nl

View file

@ -0,0 +1,20 @@
var benchmark = frequire('Benchmark')
func fac_rec(n) {
n == 0 ? 1 : (n * __FUNC__(n - 1))
}
func fac_iter(n) {
var prod = 1
n.times { |i|
prod *= i
}
prod
}
var result = benchmark.timethese(-3, Hash(
'fac_rec' => { fac_rec(20) },
'fac_iter' => { fac_iter(20) },
))
benchmark.cmpthese(result)

View file

@ -0,0 +1,3 @@
time 1+1
30000/1000000 # in microseconds
=> 2