Skip to content

Instantly share code, notes, and snippets.

@joinr
Created February 10, 2021 00:02
Show Gist options
  • Save joinr/11b1214ff0568c605558633525127579 to your computer and use it in GitHub Desktop.
Save joinr/11b1214ff0568c605558633525127579 to your computer and use it in GitHub Desktop.
{:deps {overload-fn/overload-fn {:mvn/version "0.1.0"}
fastmeth/fastmeth {:mvn/version "0.1.0-SNAPSHOT"}
criterium/criterium {:mvn/version "0.4.6"}}
:aliaes {;; See https://github.com/cognitect-labs/REBL-distro/wiki/REBL-and-nREPL
:nREPL {:extra-deps {nrepl/nrepl {:mvn/version "0.6.0"}}}}}
;;fastmeth is a locally-installed lein project that cloned https://github.com/palisades-lakes/faster-multimethods
;;and sets it up as a mixed clj/java project, since the version on clojars couldn't be resolved.
;;Drop me a line if anyone wants it posted.
(ns test
(:require [criterium.core :as c]
[fastmeth.core :as plm]
[overload-fn.core :as of]))
(defn add-base [x y z]
(+ x y z))
;; test> (c/quick-bench (add-base 1 2 3))
;; Evaluation count : 33268992 in 6 samples of 5544832 calls.
;; Execution time mean : 15.896539 ns
(of/defn add
([^Double x y z]
(+ x y z))
([^Long x y z]
(+ x y z)))
;; test> (c/quick-bench (add 1 2 3))
;; Evaluation count : 31557078 in 6 samples of 5259513 calls.
;; Execution time mean : 18.496599 ns
(of/defn add2
([^Double x ^Long y z]
(+ x y z))
([^Long x ^Long y z]
(+ x y z)))
;; test> (c/quick-bench (add2 1 2 3))
;; Evaluation count : 1114176 in 6 samples of 185696 calls.
;; Execution time mean : 531.956361 ns
(plm/defmulti add3
"Test for general set intersection."
{}
plm/signature
:hierarchy false)
(plm/defmethod add3
(plm/to-signature Double Long Object)
[^Double x ^Long y z]
(+ x y z))
(plm/defmethod add3
(plm/to-signature Long Long Object)
[^Long x ^Long y z]
(+ x y z))
;; test> (c/quick-bench (add3 1 2 3))
;; Evaluation count : 19636158 in 6 samples of 3272693 calls.
;; Execution time mean : 28.834515 ns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment