Skip to content

Commit

Permalink
Performance testing expressions with Criterium
Browse files Browse the repository at this point in the history
Using the Criterium library to measure the performance of expressions in
Clojure.  Very useful for analysing parts of your code to see how quick they are
to run.
  • Loading branch information
practicalli-johnny committed Oct 16, 2018
1 parent 513c072 commit 7940e9b
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/clojure_through_code/benchmark.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
(ns clojure-through-code.benchmark
(:require [criterium.core :refer [quick-bench]]))


;; cond
(let [number 5]
(quick-bench (cond = 5 1 1 2 2 3 3 4 4 5 5)))

;; Evaluation count : 50788488 in 6 samples of 8464748 calls.
;; Execution time mean : 2.535916 ns
;; Execution time std-deviation : 0.096838 ns
;; Execution time lower quantile : 2.435814 ns ( 2.5%)
;; Execution time upper quantile : 2.686146 ns (97.5%)
;; Overhead used : 9.431514 ns

;; Found 1 outliers in 6 samples (16.6667 %)
;; low-severe 1 (16.6667 %)
;; Variance from outliers : 13.8889 % Variance is moderately inflated by outliers


(let [number 5]
(quick-bench (condp = 5 1 1 2 2 3 3 4 4 5 5)))

;; Evaluation count : 3625284 in 6 samples of 604214 calls.
;; Execution time mean : 156.813816 ns
;; Execution time std-deviation : 2.560629 ns
;; Execution time lower quantile : 154.222522 ns ( 2.5%)
;; Execution time upper quantile : 160.425030 ns (97.5%)
;; Overhead used : 9.431514 ns

;; Found 1 outliers in 6 samples (16.6667 %)
;; low-severe 1 (16.6667 %)
;; Variance from outliers : 13.8889 % Variance is moderately inflated by outliers



(let [number 5]
(quick-bench (case 5 1 1 2 2 3 3 4 4 5 5)))

;; Evaluation count : 56533626 in 6 samples of 9422271 calls.
;; Execution time mean : 1.158650 ns
;; Execution time std-deviation : 0.187322 ns
;; Execution time lower quantile : 1.021431 ns ( 2.5%)
;; Execution time upper quantile : 1.471115 ns (97.5%)
;; Overhead used : 9.431514 ns

;; Found 1 outliers in 6 samples (16.6667 %)
;; low-severe 1 (16.6667 %)
;; Variance from outliers : 47.5092 % Variance is moderately inflated by outliers

0 comments on commit 7940e9b

Please sign in to comment.