Thanks to swdcom which buffers 512 characters and then sends them to the terminal, we should be able to see how long various Words take to run.
Elapsed Time Using the Systick Timer
I have implemented a 1 millisecond Systick timer in this Forth kernel so we will use that for the tests.
ticktime. 1900924 ok. ticktime. 1903227 ok. ticktime. 1904346 ok. ticktime. 1905309 ok. ticktime. 1906227 ok. ticktime. 1906990 ok. ticktime. 1907571 ok.
It has a function to reset the counter to zero before a new elapsed time measurement. Here you can see it takes me 1150 ms to manually reset the timer and then measure the time it took:
zero-ticktime ok. ticktime. 1150 ok.
Testing bf@
Now design a new word "test-bf@" and time how long it takes to run.
First, test the inherent delay in the ticktime system ?
: test-ticktime ( -- x) zero-ticktime ticktime. ;
Now we run it and see that the inherent delay time is under 1 millisecond.
test-ticktime 0 ok.
bf@
Now test bf@
: time-bf@ zero-ticktime $48000000 2 2 bf@ ticktime. ;
time-bf@ 0 ok.
If printing the bitfield value is included, it's somewhere around 1 millisecond.
: time-bf@@ zero-ticktime $48000000 2 2 bf@ bin. ticktime. ; ok. time-bwm@ 3322222222221111111111 10987654321098765432109876543210 00000000000000000000000000000011 1 ok.
Testing bfs! and bfc!
: test-bfs! zero-ticktime $40021014 ( 1 ) 20 1 bfs! ticktime. ;
Time was under 1 ms for both test-bfs! and test-bfc!.
test-bfs! 0 ok.
How about measuring the elapsed time with a microsecond timer ?