Skip to content

Instantly share code, notes, and snippets.

Nathan Marz nathanmarz

Block or report user

Report or block nathanmarz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
nathanmarz / repl
Created Jul 31, 2019
Multiple namespace loading behavior
View repl
user=> (require 'test-ns)
user=> (require 'test-ns)
user=> (require 'test_ns)
user=> (require 'test_ns)
View gist:0bec01582868ba8c7fd7a589a5bb4cc4
### Keybase proof
I hereby claim:
* I am nathanmarz on github.
* I am nathanmarz ( on keybase.
* I have a public key ASC_ykwTrU3q__CBRbHWiRnZZf_Hg8ZSu9ye2a3nM4NU9Qo
To claim this, I am signing this object:
nathanmarz / ensure.clj
Created Dec 20, 2017
Remove empty subvalues
View ensure.clj
(let [ensure* (stay-then-continue (if-path empty? (terminal-val NONE)))]
(defdynamicnav ensure [& path]
(interleave (repeat (count path) ensure*) path)
(setval [:a (ensure :b :c)] NONE {:a {:b {:c 1}}})
;; => {}
(setval [:a (ensure :b :c)] NONE {:a {:b {:c 1} :d 2}})
;; => {:a {:d 2}}
View gist:9d8805d5e7d9c689cd629bd0551e84f1
Benchmark code:
Benchmark: first value of a size 10 vector (10000000 iterations)
Avg(ms) vs best Code
261.98 1.00 (select-any FIRST data)
277.11 1.06 (select-any ALL data)
337.43 1.29 (select-first ALL data)
561.89 2.14 (first data)
nathanmarz / benchmark.clj
Last active Mar 1, 2017
namespace qualify keys of a map benchmark
View benchmark.clj
Specter 1.0
Clojure 1.8.0
Mac OSX 10.11.6
Benchmark: namespace qualify keys of a small map (1000000 iterations)
Avg(ms) vs best Code
243.69 1.00 (setval [MAP-KEYS NAMESPACE] (str *ns*) data)
432.11 1.77 (reduce-kv (fn [m k v] (assoc m (keyword (str *ns*) (name k)) v)) {} data)
682.69 2.80 (into {} (map (fn [[k v]] [(keyword (str *ns*) (name k)) v])) data)
nathanmarz / results-clojure-1.7.0.clj
Last active Apr 29, 2019
Specter 0.13.0 benchmark
View results-clojure-1.7.0.clj
Benchmark code at:
Run against Clojure 1.7.0 and Java 1.7.0 on Mac OSX 10.11.6
Benchmark: get value in nested map (2500000 iterations)
Avg(ms) vs best Code
53.528 1.00 (-> data (get :a) (get :b) (get :c))
54.708 1.02 (-> data :a :b :c)
View fast-constantly.clj
(defn fast-constantly [v]
(fn ([] v)
([a1] v)
([a1 a2] v)
([a1 a2 a3] v)
([a1 a2 a3 a4] v)
([a1 a2 a3 a4 a5] v)
([a1 a2 a3 a4 a5 a6] v)
([a1 a2 a3 a4 a5 a6 a7] v)
([a1 a2 a3 a4 a5 a6 a7 a8] v)
View map-vals-clojure-benchmark.txt
Benchmark: transform values of a small map (1000000 iterations)
Avg(ms) vs best Code
141.61 1.00 (map-vals-map-iterable data inc)
146.86 1.04 (reduce-kv (fn [m k v] (assoc m k (inc v))) {} data)
156.66 1.11 (reduce-kv (fn [m k v] (assoc m k (inc v))) (empty data) data)
161.20 1.14 (transform MAP-VALS inc data)
211.53 1.49 (persistent! (reduce-kv (fn [m k v] (assoc! m k (inc v))) (transient {}) data))
227.91 1.61 (map-vals-map-iterable-transient data inc)
332.09 2.35 (transform [ALL LAST] inc data)
View example.clj
(declarepath ConawWalker)
(providepath ConawWalker
(cond-path map? MAP-VALS coll? ALL)
(transform [ALL MAP-VALS ConawWalker (pred :tempid)] :tempid data)
View wrap-implicit-lists.clj
;; given this data structure
(def data
[{:type :root,
[{:line-type :comment, :text "#+title: Sample Org File"}
{:line-type :comment, :text "#+author: Seylerius"}
{:line-type :blank, :text ""}
{:line-type :paragraph,
:text "This is an attempt to test Org-Mode processing."}
{:line-type :blank, :text ""}]}
You can’t perform that action at this time.