Created
July 14, 2017 18:51
-
-
Save Sophia-Gold/3021666cbcc0f56a5fcd0ec6bc126cf8 to your computer and use it in GitHub Desktop.
This file contains 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
(name :foo/bar) | |
(namespace :foo/bar) | |
(namespace (keyword (name :foo/bar/baz))) | |
(keyword "foo" "bar/baz") | |
(keyword "foo" (str (keyword "bar" "baz"))) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(use 'criterium.core) | |
(quick-bench (namespace :foo/bar)) ;; 3.566772 ns | |
(quick-bench (clojure.string/split (str :foo/bar) #"/")) ;; 169.893638 ns | |
(quick-bench (namespace (keyword (name :foo/bar/baz)))) ;; 51.160878 ns | |
(quick-bench (clojure.string/split (str :foo/bar/baz) #"/")) ;; 211.924696 ns | |
;; scales linearly | |
(quick-bench (namespace (keyword (name (keyword (name (keyword (name :foo/bar/baz/qux/quz)))))))) ;; 153.071653 ns | |
(quick-bench (clojure.string/split (str :foo/bar/baz/qux/quz) #"/")) ;; 290.058293 ns | |
;; slower at 11 levels of nesting | |
(quick-bench (namespace (keyword (name (keyword (name (keyword (name (keyword (name (keyword (name (keyword (name (keyword (name (keyword (name (keyword (name :foo/bar/baz/qux/quux/quuz/corge/grault/garply/waldo/fred)))))))))))))))))))) ;; 630.593118 ns | |
(quick-bench (clojure.string/split (str :foo/bar/baz/qux/quux/quuz/corge/grault/garply/waldo/fred) #"/")) ;; 614.892063 ns | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; scales linearly | |
(quick-bench (keyword "foo" "bar")) ;; 18.681389 ns | |
(quick-bench (keyword "foo" (str (keyword "bar" "baz")))) ;; 32.015719 ns | |
(quick-bench (keyword "foo" (str (keyword "bar" (str (keyword "baz" "qux")))))) ;; 51.849270 ns | |
;; vs. str | |
(quick-bench (keyword "foo" (str (keyword "bar" "baz")))) ;; 32.015719 ns | |
(quick-bench (keyword "foo" (str "bar/" "baz"))) ;; 77.870166 ns | |
(quick-bench (keyword (str "foo/" "bar/" "baz"))) ;; 127.062484 ns |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment