API for profile - clojure-contrib v1.2 (stable)

by Stuart Sierra

Full namespace name: clojure.contrib.profile

Overview

Simple code profiling & timing measurement.

Wrap any section of code in the prof macro, giving it a name, like this:

       (defn my-function [x y]
         (let [sum (prof :addition (+ x y))
               product (prof :multiplication (* x y))]
           [sum product]))

The run your code in the profile macro, like this:

       (profile (dotimes [i 10000] (my-function 3 4)))

Which prints a report for each named section of code:

          Name      mean       min       max     count       sum
      addition       265         0     37000     10000   2655000
multiplication       274         0     53000     10000   2747000

Times are measured in nanoseconds, to the maximum precision available
under the JVM.  See the function documentation for more details.

Public Variables and Functions



*enable-profiling*

var

  
Set this to false before loading/compiling to omit
profiling code.
Source


print-summary

function
Usage: (print-summary profile-summary)
Prints a table of the results returned by summarize.
Source


prof

macro
Usage: (prof name & body)
If *enable-profiling* is true, wraps body in profiling code.
Returns the result of body. Profile timings will be stored in
*profile-data* using name, which must be a keyword, as the key.
Timings are measured with System/nanoTime.
Source


profile

macro
Usage: (profile & body)
Runs body with profiling enabled, then prints a summary of
results.  Returns nil.
Source


summarize

function
Usage: (summarize profile-data)
Takes the raw data returned by with-profile-data and returns a map
from names to summary statistics.  Each value in the map will look
like:

   {:mean ..., :min ..., :max ..., :count ..., :sum ...}

:mean, :min, and :max are how long the profiled section took to run,
in nanoseconds.  :count is the total number of times the profiled
section was executed.  :sum is the total amount of time spent in the
profiled section, in nanoseconds.
Source


with-profile-data

macro
Usage: (with-profile-data & body)
Executes body with *profile-data* bound to an atom of a new map.
Returns the raw profile data as a map.  Keys in the map are profile
names (keywords), and values are lists of elapsed time, in
nanoseconds.
Source
Logo & site design by Tom Hickey.
Clojure auto-documentation system by Tom Faulhaber.