Created
September 4, 2019 11:57
-
-
Save danielneal/c54838842db2f83b72406ee583625d3b to your computer and use it in GitHub Desktop.
Speed test async storage
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 speed-test.core) | |
(defn random-map | |
"Generates a random map with provided depth and length" | |
[opts] | |
(let [{:keys [depth length random-key random-val] | |
:or {depth 2 | |
length 20 | |
kfn #(rand-int 20) | |
vfn #(rand-int 20)}} opts] | |
(into {} | |
(for [k (range length)] | |
[(kfn) (if (> depth 1) | |
(random-map (update opts :depth dec)) | |
(vfn))])))) | |
(defn test-spec [opts] | |
(let [{:keys [n]} opts] | |
(distinct-by | |
:maps-per-key | |
(map (fn [x] | |
{:number-of-keys x | |
:maps-per-key (Math/ceil (/ n x))}) (range 1 (inc n)))))) | |
(defn run-speed-test | |
[] | |
(doseq [opts (test-spec {:n 1000}) | |
:let [{:keys [number-of-keys maps-per-key]} opts | |
data (into {} | |
(for [i (range number-of-keys)] | |
[(str "n=" i) | |
(pr-str (mapv random-map (range maps-per-key)))]))]] | |
(time | |
(write data)) | |
(time | |
(read (keys data))) | |
(time | |
(delete (keys data))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment