Skip to content

Instantly share code, notes, and snippets.

@jiacai2050
Created October 8, 2017 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiacai2050/cdaaffa93079a4b8451727ace0c13064 to your computer and use it in GitHub Desktop.
Save jiacai2050/cdaaffa93079a4b8451727ace0c13064 to your computer and use it in GitHub Desktop.
(ns demo.record
(:require [criterium.core :refer [bench with-progress-reporting]]))
(def a-z-ks (map (comp keyword str) (seq "abcdefghijklmnopqrstuwvxyz")))
(def dummy-map (zipmap a-z-ks (range)))
(defmacro alphabet-macro []
`(do
(defrecord ~'Alphabet [~@(map (comp symbol str) a-z-ks)])
(def ~'dummy-record (~'Alphabet. ~@(range 26)))))
(alphabet-macro)
(with-progress-reporting (bench
(doseq [k a-z-ks]
(get dummy-map k))))
;; Evaluation count : 35047440 in 60 samples of 584124 calls.
;; Execution time mean : 1.748119 µs
;; Execution time std-deviation : 47.972714 ns
;; Execution time lower quantile : 1.691436 µs ( 2.5%)
;; Execution time upper quantile : 1.880925 µs (97.5%)
;; Overhead used : 2.179973 ns
;; Found 3 outliers in 60 samples (5.0000 %)
;; low-severe 3 (5.0000 %)
;; Variance from outliers : 14.2220 % Variance is moderately inflated by outliers
(with-progress-reporting (bench
(doseq [k a-z-ks]
(get dummy-record k))))
;; Evaluation count : 17245380 in 60 samples of 287423 calls.
;; Execution time mean : 3.398654 µs
;; Execution time std-deviation : 80.611687 ns
;; Execution time lower quantile : 3.286580 µs ( 2.5%)
;; Execution time upper quantile : 3.637143 µs (97.5%)
;; Overhead used : 2.179973 ns
;; Found 3 outliers in 60 samples (5.0000 %)
;; low-severe 2 (3.3333 %)
;; low-mild 1 (1.6667 %)
;; Variance from outliers : 11.0366 % Variance is moderately inflated by outliers
@jiacai2050
Copy link
Author

After fix alphabet-macro (change str to name in comp), the result is as expected

Evaluation count : 32090880 in 60 samples of 534848 calls.
             Execution time mean : 1.881154 µs
    Execution time std-deviation : 121.068410 ns
   Execution time lower quantile : 1.797369 µs ( 2.5%)
   Execution time upper quantile : 2.290917 µs (97.5%)
                   Overhead used : 2.307427 ns

Found 7 outliers in 60 samples (11.6667 %)
	low-severe	 1 (1.6667 %)
	low-mild	 6 (10.0000 %)
 Variance from outliers : 48.4282 % Variance is moderately inflated by outliers 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment