Print statistics +s,-s
Normally, Hugs just shows the result of evaluating each expression:
Prelude> map (\x -> x*x) [1..10]
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Prelude> [1..]
[1, 2, 3, 4, {Interrupted!}
Prelude>
With the +s option, the interpreter will also display statistics
about the total number of reductions and cells; the
former gives a measure of the work done, while the latter gives an
indication of the amount of memory used. For example:
Prelude> :set +s
Prelude> map (\x -> x*x) [1..10]
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
(248 reductions, 429 cells)
Prelude> [1..]
[1, 2, 3, 4, {Interrupted!}
(18 reductions, 54 cells)
Prelude>
Note that the statistics produced by +s are an extremely crude
measure of the behaviour of a program, and can easily be misinterpreted.
For example:
- The fact that one expression requires more reductions than another does
not necessarily mean that the first is slower; some reductions
require much more work than others, and it may be that the average cost
of reductions in the first expression is much lower than the average
for the second.
- The cell count does not give any information about residency,
which is the number of cells that are being used at any given time. For
example, it does not distinguish between computations that run in constant
space and computations with residency proportional to the size of the
input.
One reasonable use of the statistics produced by +s would be to
observe general trends in the behaviour of a single algorithm with
variations in its input.