aboutsummaryrefslogtreecommitdiffstats
path: root/forth
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2023-11-08 15:31:44 -0500
committerClyne Sullivan <clyne@bitgloo.com>2023-11-08 15:31:44 -0500
commitb33c0c564c51252ff241a2143e467dadfb8d8994 (patch)
tree1e090f690843d9daf9c3fda7e08187bc7ea9fadb /forth
parent8e7cb05cfb2903e3c6a3e0bf713282cf50563590 (diff)
fib.fth benchmark; some minor coreword optimizations
Diffstat (limited to 'forth')
-rw-r--r--forth/fib.fth19
1 files changed, 19 insertions, 0 deletions
diff --git a/forth/fib.fth b/forth/fib.fth
new file mode 100644
index 0000000..82c87cd
--- /dev/null
+++ b/forth/fib.fth
@@ -0,0 +1,19 @@
+: fib ( n -- d )
+ >r 0 dup 1 0 r> 0 do
+ 2dup 2>r 2swap 6 sys 2r> 2swap loop 2drop ;
+
+: fibtest ( n -- )
+ 0 do i fib <# #s #> type space loop ;
+
+: fibbench ( n -- )
+ 5 sys fib 5 sys >r 2drop r> ;
+
+variable avg 0 avg !
+100 constant iters
+
+: bench ( -- )
+ iters 0 do 100 fibbench avg +! loop
+ avg @ iters / avg ! ;
+
+bench ." avg time: " avg @ . ." us" cr
+bye