ave-time ( quot n -- )


Vocabulary
project-euler.ave-time

Inputs
quota quotation
nan integer


Outputs
None

Word description
Runs a quotation n times, then prints the average run time and standard deviation.

Notes
The stack effect of quot is accounted for and only one set of outputs will remain on the stack no matter how many trials are run.

Examples
This word can be used to compare performance of the non-optimizing and optimizing compilers.

First, we time a quotation directly; quotations are compiled by the non-optimizing quotation compiler:
[ 1000000 0 [ + ] reduce drop ] 10 ave-time
465 ms ave run time - 13.37 SD (10 trials)

Now we define a word and compile it with the optimizing word compiler. This results in faster execution:
: foo 1000000 0 [ + ] reduce ; \ foo compile [ foo drop ] 10 ave-time
202 ms ave run time - 22.73 SD (10 trials)


Definition