From b33c0c564c51252ff241a2143e467dadfb8d8994 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 8 Nov 2023 15:31:44 -0500 Subject: fib.fth benchmark; some minor coreword optimizations --- forth/fib.fth | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 forth/fib.fth (limited to 'forth') 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 -- cgit v1.2.3