Skip to content

Commit e8225f0

Browse files
authored
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
1 parent a379893 commit e8225f0

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

DEVELOPER.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,16 @@ lein do clean, test
1010
lein javac
1111
lein doo node test-build once
1212
```
13+
14+
# Running benchmarks
15+
## All benchmarks
16+
```
17+
scripts/run-benchmarks
18+
```
19+
## Individual benchmark(s)
20+
Specify the benchmark names as command line args. They will likely each need quoted because they contain spaces.
21+
Order is ignored.
22+
```
23+
scripts/run-benchmarks "prepend to a vector" "filter a sequence"
24+
```
25+

scripts/benchmarks.clj

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919
(println (pretty-float3 t) "\t\t" (pretty-float3 (/ t best-time 1.0)) "\t\t" k))))
2020

2121
(defmacro run-benchmark [name & exprs]
22-
(let [afn-map (->> exprs shuffle (map (fn [e] [`(quote ~e) `(fn [] ~e)])) (into {}))]
23-
`(do
24-
(println "Benchmark:" ~name)
25-
(compare-benchmark ~afn-map)
26-
(println "\n********************************\n"))))
22+
(let [only-benchmarks (set (filter some? *command-line-args*))
23+
all-benchmarks? (empty? only-benchmarks)]
24+
(if (or all-benchmarks? (contains? only-benchmarks name))
25+
(let [afn-map (->> exprs shuffle (map (fn [e] [`(quote ~e) `(fn [] ~e)])) (into {}))]
26+
`(do
27+
(println "Benchmark:" ~name)
28+
(compare-benchmark ~afn-map)
29+
(println "\n********************************\n"))))))
2730

2831
(defn specter-dynamic-nested-get [data a b c]
2932
(select-any (keypath a b c) data))

scripts/run-benchmarks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ lein version
55
echo
66
lein show-profiles bench
77
echo
8-
java -server -XX:MaxInlineSize=100 -cp "$(lein with-profile bench classpath)" clojure.main scripts/benchmarks.clj
8+
java -server -XX:MaxInlineSize=100 -cp "$(lein with-profile bench classpath)" clojure.main scripts/benchmarks.clj "$@"

0 commit comments

Comments
 (0)