From e8225f0e5883746c2fd17612c42334ccda6cc73d Mon Sep 17 00:00:00 2001 From: Jeff Evans Date: Thu, 22 Oct 2020 16:51:04 -0500 Subject: [PATCH] Make it possible to run individual benchmark(s) (#298) Parse command line args to benchmarks.clj and treat them as benchmark names to run Add information on running benchmarks to DEVELOPER.md --- DEVELOPER.md | 13 +++++++++++++ scripts/benchmarks.clj | 13 ++++++++----- scripts/run-benchmarks | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/DEVELOPER.md b/DEVELOPER.md index 0752ba75..d8a32c82 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -10,3 +10,16 @@ lein do clean, test lein javac lein doo node test-build once ``` + +# Running benchmarks +## All benchmarks +``` +scripts/run-benchmarks +``` +## Individual benchmark(s) +Specify the benchmark names as command line args. They will likely each need quoted because they contain spaces. +Order is ignored. +``` +scripts/run-benchmarks "prepend to a vector" "filter a sequence" +``` + diff --git a/scripts/benchmarks.clj b/scripts/benchmarks.clj index 1108b710..347afff4 100644 --- a/scripts/benchmarks.clj +++ b/scripts/benchmarks.clj @@ -19,11 +19,14 @@ (println (pretty-float3 t) "\t\t" (pretty-float3 (/ t best-time 1.0)) "\t\t" k)))) (defmacro run-benchmark [name & exprs] - (let [afn-map (->> exprs shuffle (map (fn [e] [`(quote ~e) `(fn [] ~e)])) (into {}))] - `(do - (println "Benchmark:" ~name) - (compare-benchmark ~afn-map) - (println "\n********************************\n")))) + (let [only-benchmarks (set (filter some? *command-line-args*)) + all-benchmarks? (empty? only-benchmarks)] + (if (or all-benchmarks? (contains? only-benchmarks name)) + (let [afn-map (->> exprs shuffle (map (fn [e] [`(quote ~e) `(fn [] ~e)])) (into {}))] + `(do + (println "Benchmark:" ~name) + (compare-benchmark ~afn-map) + (println "\n********************************\n")))))) (defn specter-dynamic-nested-get [data a b c] (select-any (keypath a b c) data)) diff --git a/scripts/run-benchmarks b/scripts/run-benchmarks index 02ca20b0..5fbe929f 100755 --- a/scripts/run-benchmarks +++ b/scripts/run-benchmarks @@ -5,4 +5,4 @@ lein version echo lein show-profiles bench echo -java -server -XX:MaxInlineSize=100 -cp "$(lein with-profile bench classpath)" clojure.main scripts/benchmarks.clj +java -server -XX:MaxInlineSize=100 -cp "$(lein with-profile bench classpath)" clojure.main scripts/benchmarks.clj "$@"