Skip to content

Commit

Permalink
let CIs also benchmark the solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
narimiran committed Sep 13, 2024
1 parent b8737e5 commit 7258ba2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
kind: [tests, benchmark]
fail-fast: false

runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -38,7 +39,13 @@ jobs:
restore-keys: cljdeps-

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

- name: Test solutions
if : ${{ matrix.kind == 'tests' }}
run: clojure -M clojure/tests/solutions_tests.clj

- name: Benchmark solutions
if : ${{ matrix.kind == 'benchmark' }}
run: clojure -M:profile clojure/tests/solutions_benchmark.clj
37 changes: 37 additions & 0 deletions clojure/tests/solutions_benchmark.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(ns solutions-benchmark
(:require
[criterium.core :as c]
[clojure.string :as str]
[clojure.pprint :as pp]
aoc
day01 day02 day03 day04 day05
day06 day07 day08 day09 day10
day11 day12 day13 day14 day15
day16 day17 day18 day19 day20
day21 day22 day23 day24 day25))


(defn extract-time [res]
(->> res
str/split-lines
second
(drop-while #(not (#{\:} %)))
rest
str/join))

(def results (atom []))

(def first-day 1)
(def last-day 25)

(doseq [i (range first-day (inc last-day))]
(println "BENCHMARKING DAY" i)
(let [res (with-out-str
(c/quick-bench ((eval (symbol (format "day%02d" i) "solve")) (aoc/read-file i))))]
(println res)
(swap! results conj {:day i :time (extract-time res)}))
(println "\n\n\n"))


(println "SUMMARY:\n")
(pp/print-table @results)

0 comments on commit 7258ba2

Please sign in to comment.