Re: timing a word

From: Ron Oliver <ron_at_forth.com>
Date: Tue, 02 Feb 2010 11:56:01 -0500

Roger Levy wrote:
> could write one pretty simply:
> : time utimer ' execute utimer 2swap d- d. ;
>
> not sure of the semantics but i think that's all you need?

Not quite like that. uCOUNTER provides the starting value; uTIMER
prints the difference between the current and uCOUNTER values.

Also, unless you're profiling a dictionary lookup, you wouldn't want
to put the ' in the timing...the dictionary lookup may take longer
than the word under test.

TIME is a SwiftForth system word, so I'll call it PROFILE instead.

Assuming the word under test has no stack effect, you could write it
like this:

: PROFILE ( <word> -- ) ' uCOUNTER ROT EXECUTE uTIMER ;

\ <word> indicates a word is being consumed from the input stream (by ')

Better still, if you can run your word multiple times, do that so that
you're mostly measuring the time your word takes:

: PROFILE ( <word> u -- ) ' SWAP uCOUNTER
    2SWAP 0 DO DUP EXECUTE LOOP DROP uTIMER ;

e.g.: to test FOO:
1000 FOO PROFILE \ print time required to run FOO 1000 times

Hope this helps.

-Ron
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and
bug reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Tue Feb 02 2010 - 08:56:31 PST


Subscribe to our e-mail list service. It's free for all SwiftForth and SwiftX users!

This archive was generated 07-Feb-2012. Archive updated nightly.