Profiling time and allocations
Profiling in the presence of lazy evaluation does not differ much from profiling always-strict programs. The profiler that comes with GHC assigns time and space usages to cost centres. Cost centres annotate expressions, and can be set either manually or automatically by GHC. Cost centres can occur enclosed in other cost centres recursively, forming cost centre stacks. All time and space costs accumulate in each enclosing cost centre.
Cost centres can be set manually via annotations, or automatically by GHC via compiler flags. Depending on how often the cost centre is entered, the choice of cost centre can have a big impact on overall execution time. Fortunately, allocation profiling is not affected by chosen cost centers.
Setting cost centres manually
Let's start our profiling journey with a basic example. The following program uses the simple moving average function we wrote in the first chapter:
-- file: prof-basics.hs sma :: [Double] -> [Double] sma...