macrochrono /

Filename Size Date modified Message
900 B
32 B
638 B
1.4 KB
2.3 KB
406 B


A small collection of time measuring & benchmarking macros for Clojure.


Leiningen dependency:

[com.postspectacular/macrochrono "0.1.0"]

There are currently only two macro available to measure a single execution or to benchmark a number of iterations. In both cases the timings are given in milliseconds. timed-action returns a 2-element vector of the expression's result followed by its execution time.

(use 'macrochrono)
(timed-action (reduce + (range 1 100001)))
[5000050000 5.784]

The bench macro evaluates a given expression several times, discards the result and returns a map of execution time statistics:

(bench 1000 (reduce + (range 1 100001)))
{:median 5.1579999999999995, :max 9.091, :min 4.677, :avg 5.633388000000003}

Adding an additional "verbose" flag, each intermediate timing is printed to out.

(bench 10 (reduce + (range 1 100001)) true)
"Elapsed time: 6.021 msecs"
"Elapsed time: 8.251 msecs"
"Elapsed time: 5.162999999999999 msecs"
"Elapsed time: 5.269 msecs"
"Elapsed time: 6.8759999999999994 msecs"
"Elapsed time: 8.251999999999999 msecs"
"Elapsed time: 6.112 msecs"
"Elapsed time: 5.0169999999999995 msecs"
"Elapsed time: 6.927 msecs"
"Elapsed time: 5.637 msecs"
{:median 6.112, :max 8.251999999999999, :min 5.0169999999999995, :avg 6.3525}


Copyright © 2012 Karsten Schmidt

Distributed under the Eclipse Public License, the same as Clojure.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.