Skip to content

Commit ced8380

Browse files
committed
let CIs also benchmark the solutions
1 parent b8737e5 commit ced8380

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

.github/workflows/test.yml

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ jobs:
77
strategy:
88
matrix:
99
os: [ubuntu-latest]
10+
kind: [tests, benchmark]
1011
fail-fast: false
1112

1213
runs-on: ${{ matrix.os }}
@@ -38,7 +39,13 @@ jobs:
3839
restore-keys: cljdeps-
3940

4041
- name: Test helpers
42+
if : ${{ matrix.kind == 'tests' }}
4143
run: clojure -M clojure/tests/aoc_tests.clj
4244

4345
- name: Test solutions
46+
if : ${{ matrix.kind == 'tests' }}
4447
run: clojure -M clojure/tests/solutions_tests.clj
48+
49+
- name: Benchmark solutions
50+
if : ${{ matrix.kind == 'benchmark' }}
51+
run: clojure -M:profile clojure/tests/solutions_benchmark.clj

clojure/tests/solutions_benchmark.clj

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
(ns solutions-benchmark
2+
(:require
3+
[criterium.core :as c]
4+
[clojure.string :as str]
5+
[clojure.pprint :as pp]
6+
aoc
7+
day01 day02 day03 day04 day05
8+
day06 day07 day08 day09 day10
9+
day11 day12 day13 day14 day15
10+
day16 day17 day18 day19 day20
11+
day21 day22 day23 day24 day25))
12+
13+
14+
(defn extract-time [res]
15+
(->> res
16+
str/split-lines
17+
second
18+
(drop-while #(not (#{\:} %)))
19+
rest
20+
str/join))
21+
22+
(def results (atom []))
23+
24+
(def first-day 1)
25+
(def last-day 3)
26+
27+
(doseq [i (range first-day (inc last-day))]
28+
(println "BENCHMARKING DAY" i)
29+
(let [res (with-out-str
30+
(c/quick-bench ((eval (symbol (format "day%02d" i) "solve")) (aoc/read-file i))))]
31+
(println res)
32+
(swap! results conj {:day i :time (extract-time res)}))
33+
(println "\n\n\n"))
34+
35+
36+
(println "SUMMARY:\n")
37+
(pp/print-table @results)

0 commit comments

Comments
 (0)