Last active
January 26, 2019 12:26
-
-
Save serioga/2307903e450d82c1d71e5ab5e74c304a to your computer and use it in GitHub Desktop.
Benchmark for mutimethods. See updated version at https://github.com/serioga/clojure-benhcmarks/blob/master/src/clojure_benchmarks/multimethods.clj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns user | |
(:require | |
[criterium.core :as criterium])) | |
(set! *warn-on-reflection* true) | |
(defmulti test-multi :type) | |
(defmethod test-multi :a [m] m) | |
(defmethod test-multi :b [m] m) | |
(defmethod test-multi :c [m] m) | |
(defn test-type-a [m] m) | |
(defn test-type-b [m] m) | |
(defn test-type-c [m] m) | |
(defn test-condp | |
[m] | |
(condp = (:type m) | |
:a (test-type-a m) | |
:b (test-type-b m) | |
:c (test-type-c m))) | |
(defn test-case | |
[m] | |
(case (:type m) | |
:a (test-type-a m) | |
:b (test-type-b m) | |
:c (test-type-c m))) | |
(defn test-map | |
[m] | |
(let [dispatch {:a test-type-a | |
:b test-type-b | |
:c test-type-c} | |
f (get dispatch (:type m))] | |
(f m))) | |
(comment | |
(criterium/quick-bench | |
(test-multi {:type :a}) | |
(test-multi {:type :b}) | |
(test-multi {:type :c})) | |
; Evaluation count : 13892178 in 6 samples of 2315363 calls. | |
; Execution time mean : 43,611754 ns | |
; Execution time std-deviation : 6,145586 ns | |
; Execution time lower quantile : 40,490039 ns ( 2,5%) | |
; Execution time upper quantile : 54,277875 ns (97,5%) | |
; Overhead used : 1,813294 ns | |
(criterium/quick-bench | |
(test-condp {:type :a}) | |
(test-condp {:type :b}) | |
(test-condp {:type :c})) | |
; Evaluation count : 44715384 in 6 samples of 7452564 calls. | |
; Execution time mean : 11,760601 ns | |
; Execution time std-deviation : 0,174020 ns | |
; Execution time lower quantile : 11,602599 ns ( 2,5%) | |
; Execution time upper quantile : 12,039168 ns (97,5%) | |
; Overhead used : 1,813294 ns | |
(criterium/quick-bench | |
(test-case {:type :a}) | |
(test-case {:type :b}) | |
(test-case {:type :c})) | |
; Evaluation count : 21928422 in 6 samples of 3654737 calls. | |
; Execution time mean : 26,107375 ns | |
; Execution time std-deviation : 0,824914 ns | |
; Execution time lower quantile : 25,535921 ns ( 2,5%) | |
; Execution time upper quantile : 27,510201 ns (97,5%) | |
; Overhead used : 1,813294 ns | |
(criterium/quick-bench | |
(test-map {:type :a}) | |
(test-map {:type :b}) | |
(test-map {:type :c})) | |
; Evaluation count : 20795826 in 6 samples of 3465971 calls. | |
; Execution time mean : 27,176164 ns | |
; Execution time std-deviation : 0,823958 ns | |
; Execution time lower quantile : 26,156290 ns ( 2,5%) | |
; Execution time upper quantile : 28,316935 ns (97,5%) | |
; Overhead used : 1,856009 ns | |
nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Moved to https://github.com/serioga/clojure-benhcmarks/blob/master/src/clojure_benchmarks/multimethods.clj and updated.