Skip to content

Instantly share code, notes, and snippets.

@jeroenvandijk
Last active June 12, 2020 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeroenvandijk/dcfebddd7ba9bda1ae298b29ee2f8998 to your computer and use it in GitHub Desktop.
Save jeroenvandijk/dcfebddd7ba9bda1ae298b29ee2f8998 to your computer and use it in GitHub Desktop.
Idea for multitime test in Babashka
;; Like https://github.com/ltratt/multitime but with the power of Clojure: multi-processor, shuffling, advanced statistics
;; export BABASHKA_CLASSPATH=$(clojure -Sdeps '{:deps {org.clojure/data.generators {:mvn/version "1.0.0"}, org.clojure/math.combinatorics {:mvn/version "0.1.6"}}}' -Spath)
(do
(require '[clojure.math.combinatorics :as combo]
'[clojure.data.generators :as gen])
(let [binaries ["../sci/tmp/sci-25ace7c"
"../sci/tmp/sci-3c01531"
"../sci/tmp/sci-6c8852d"]
programs '[(loop [val 0 cnt 1000000] (if (pos? cnt) (recur (inc val) (dec cnt)) val))]
n 1
combinations (apply concat (repeat n (combo/cartesian-product binaries programs)))
seed 42 #_(rand-int)]
(binding [gen/*rnd* (java.util.Random. seed)]
(let [test-results (pmap (fn [[binary program]]
(let [start (System/currentTimeMillis)
res (clojure.java.shell/sh binary "-e" (pr-str program))]
[[binary program] (cond-> {:exit (:exit res)
:elapsed (- (System/currentTimeMillis) start)
}
(not (zero? (:exit res)))
(assoc :error (:err res)))]))
(shuffle combinations))]
;; TODO do analysis here (mean, modulo, average, std dev, outliers etc)
(doseq [test-result test-results]
(println test-result))))))
@jeroenvandijk
Copy link
Author

Background here babashka/sci#349

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment