Home

Awesome

citius

A Clojure library for comparative benchmarking using Criterium.

Usage

Leiningen dependency: [citius "0.2.4"]

Requiring namespace:

(require '[citius.core :as c])

Using in tests (clojure.test)

Define use-fixtures setup:

(clojure.test/use-fixtures
  :once (c/make-bench-wrapper ["Apply" "Reduce"]
          {:chart-title "Apply vs Reduce"
           :chart-filename (format "bench-small-clj-%s.png" c/clojure-version-str)}))

Under each test, conduct the comparative benchmarking:

(deftest test-simple
  (c/compare-perf
    "concat strs" (apply str ["foo" "bar" "baz"]) (reduce str ["foo" "bar" "baz"]))
  (c/compare-perf
    "sum numbers" (apply + [1 2 3 4 5 6 7 8 9 0]) (reduce + [1 2 3 4 5 6 7 8 9 0])))

Using outside of clojure.test

Outside of clojure.test, use the with-bench-context macro:

(c/with-bench-context ["Apply" "Reduce"]
  {:chart-title "Apply vs Reduce"
   :chart-filename (format "bench-simple-clj-%s.png" c/clojure-version-str)}
  (c/compare-perf
    "concat strs" (apply str ["foo" "bar" "baz"]) (reduce str ["foo" "bar" "baz"]))
  (c/compare-perf
    "sum numbers" (apply + [1 2 3 4 5 6 7 8 9 0]) (reduce + [1 2 3 4 5 6 7 8 9 0])))

Controlling runtime behavior

You may tweak the runtime behavior of benchmarking with the following system properties and environment variables:

DescriptionChoicesDefaultJava system propertyEnvironment variable
Benchmark concurrencycomma delimited ints1 for eachcitius_concurrencyCITIUS_CONCURRENCY
Colorize summary output?true or falsetruecitius_colorizeCITIUS_COLORIZE
Criterium output formattrue or false:tabularcitius_criterium_outputCITIUS_CRITERIUM_OUTPUT
Perform quick bench?true or falsetruecitius_quick_benchCITIUS_QUICK_BENCH

For example, if the tabular Criterium output exceeds the width of your screen you may want to view it vertically:

On Unix-like systems:

CITIUS_CRITERIUM_OUTPUT=true lein with-profile clj17,bench test
# or
export CITIUS_CRITERIUM_OUTPUT=true
lein with-profile clj18,bench test

On Windows:

set CITIUS_CRITERIUM_OUTPUT=true
lein with-profile clj18,bench test

License

Copyright © 2015-2016 Shantanu Kumar (kumar.shantanu@gmail.com, shantanu.kumar@concur.com)

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.