-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.f
45 lines (38 loc) · 1.15 KB
/
tests.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
mark TESTS
variable (bench)
: bench{ ms (bench) ! ;
: }bench ms (bench) @ - . ." ms elapsed" ;
: test-do 10000000 0 do i drop loop ;
: test-for 10000000 for r@ drop next ;
: test-begin-until 10000000 R1 ! begin -1 R1 +! R1 @ 0= until ;
: test-begin-again 10000000 R1 ! begin -1 R1 +! R1 @ 0= if exit then again ;
: test-begin-until-stack 10000000 begin 1- dup 0= until drop ;
: tail-call 1- dup 0> if tail-call then drop ;
: test-tail-call 10000000 tail-call ;
: loop-tests
." testing 10 million iteration loops" cr
." testing for .. next: "
['] test-for time-it
." testing tail call: "
['] test-tail-call time-it
." testing do .. loop: "
['] test-do time-it
." testing begin .. until: "
['] test-begin-until time-it
." testing begin .. again: "
['] test-begin-again time-it
." testing begin .. until-stack: "
['] test-begin-until-stack time-it ;
variable I
variable D
: factor ( n - )
2 D ! 1 I !
>r
begin
D @ dup * r@ > if r> drop exit then
r@ D @ mod 0= if r> drop D @ exit then
I @ D +! 2 I !
again ;
\ Pure recursion test...
\
: factorial ( n - ) dup 2 > if dup 1- recurse * then ;