rslt ← {larg} (func ##.profile subs) rarg               ⍝ Performance profiling.

[profile] applies its [func]tion operand and, as  a  side-effect,  displays  the
source lines of the [sub]ject function(s) preceded by two columns of performance
information:

    hits: number of times the line in the subject function was visited
    time: percentage of total time spent in the line of the subject function

The last row of the output shows an '=' followed by the total percentage of time
spent in the function as a whole.

    123 11 func←{
    123 14     ⍵<0:⍺
     54 10     sum←⍺+⍵
     54        ⍝
     54  8     sum×2
      = 43 } ──── total time percentage for this function
      │  │ └───── function source
      │  └─────── time percentages column
      └────────── line-visits column

In common with the →time← operator, the display of profile's subject function(s)
is a side-effect of the application of its  left  operand  function. This  means
that a derived monadic operator  (profile'sub1' 'sub2' ...) can be injected into
an expression anywhere between a function and its right argument.

[A dyadic operator such as profile can be bound with a right operand to derive a
 monadic operator. This is sometimes referred to as "right operand currying"].

[profile] supersedes [mdf] and [ticks].

Examples:

    210 gcd (profile'gcd') 330              ⍝ profile of →gcd← function
6  25 gcd←{       ⍝ Greatest common divisor.
6  34     ⍵=0:|⍺
5  41     ⍵ ∇ ⍵|⍺
= 100   }

    osc←{                                   ⍝ →osc← or "snowflake" function
        1=⍵:⍵
        2|⍵:odd ⍵
        even ⍵
    }

    odd←{                                   ⍝ odd case
        osc 1+3×⍵
    }

    even←{                                  ⍝ even case
        osc ⍵÷2
    }

    P ← profile'osc' 'odd' 'even'           ⍝ derived profiling operator

    osc¨P ⍳100                              ⍝ profile of three functions
3242  9 osc←{
3242 13     1=⍵:⍵
3142 17     2|⍵:odd ⍵
2137 18     even ⍵
   = 57 }
1005  3 odd←{
1005 11     osc 1+3×⍵
   = 14 }
2137  6 even←{
2137 23     osc ⍵÷2
   = 29 }

See also: cmpx time cf

Back to: contents

Back to: Workspaces