Skip to content

Commit

Permalink
Run tests in batches and trigger a GC in between
Browse files Browse the repository at this point in the history
Hopefully this will decrease the likelyhood of running out out of memory
  • Loading branch information
iamFIREcracker committed Jan 13, 2024
1 parent 36d8023 commit e02a6f6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions aoc.asd
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#:pileup
#:split-sequence
#:st-json
#:trivial-garbage

)
:components
Expand Down
5 changes: 4 additions & 1 deletion src/utils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,10 @@

(defvar *tests* nil "A list of tests; the default argument to RUN.")

(defun run () (1am:run *tests*))
(defun run ()
(doseq (tests (subdivide *tests* 100))
(1am:run *tests*)
(trivial-garbage:gc :full t :verbose t)))

(defmacro deftest (name &body body)
"Define a test function and add it to `*tests*`."
Expand Down
1 change: 1 addition & 0 deletions vendor/make-quickutils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
:repeat
:string-ends-with-p
:string-starts-with-p
:subdivide
:subseq-
:symb
:void
Expand Down
32 changes: 27 additions & 5 deletions vendor/quickutils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
;;;; See http://quickutil.org for details.

;;;; To regenerate:
;;;; (qtlc:save-utils-as "quickutils.lisp" :utilities '(:KEEP-IF :KEEP-IF-NOT :AAND :AIF :AWHEN :BND* :BND1 :COPY-ARRAY :COPY-HASH-TABLE :DIGITS :DIVF :DOHASH :DOLISTS :DORANGE :DORANGEI :DOSEQ :DOSEQ :DOSUBLISTS :ENUMERATE :FLATTEN :HASH-TABLE-ALIST :HASH-TABLE-KEY-EXISTS-P :HASH-TABLE-KEYS :HASH-TABLE-VALUES :IF-LET :IOTA :LOOPING :MAKE-KEYWORD :MKSTR :MULF :NCYCLE :REPEAT :STRING-ENDS-WITH-P :STRING-STARTS-WITH-P :SUBSEQ- :SYMB :VOID :WHEN-LET :WHILE :WITH-GENSYMS) :ensure-package T :package "AOC.QUICKUTILS")
;;;; (qtlc:save-utils-as "quickutils.lisp" :utilities '(:KEEP-IF :KEEP-IF-NOT :AAND :AIF :AWHEN :BND* :BND1 :COPY-ARRAY :COPY-HASH-TABLE :DIGITS :DIVF :DOHASH :DOLISTS :DORANGE :DORANGEI :DOSEQ :DOSEQ :DOSUBLISTS :ENUMERATE :FLATTEN :HASH-TABLE-ALIST :HASH-TABLE-KEY-EXISTS-P :HASH-TABLE-KEYS :HASH-TABLE-VALUES :IF-LET :IOTA :LOOPING :MAKE-KEYWORD :MKSTR :MULF :NCYCLE :REPEAT :STRING-ENDS-WITH-P :STRING-STARTS-WITH-P :SUBDIVIDE :SUBSEQ- :SYMB :VOID :WHEN-LET :WHILE :WITH-GENSYMS) :ensure-package T :package "AOC.QUICKUTILS")

(eval-when (:compile-toplevel :load-toplevel :execute)
(unless (find-package "AOC.QUICKUTILS")
Expand All @@ -27,8 +27,8 @@
:WITH-GENSYMS :LOOPING :MAKE-KEYWORD
:MULF :NCYCLE :REPEAT
:STRING-ENDS-WITH-P
:STRING-STARTS-WITH-P :SUBSEQ- :VOID
:WHEN-LET :WHILE))))
:STRING-STARTS-WITH-P :SUBDIVIDE
:SUBSEQ- :VOID :WHEN-LET :WHILE))))

(defmacro abbr (short long)
"Defines a new function/macro named `short` and sharing
Expand Down Expand Up @@ -674,6 +674,28 @@ Examples:
(string= prefix s :end2 (length prefix))))


(defun subdivide (sequence chunk-size)
"Split `sequence` into subsequences of size `chunk-size`."
(check-type sequence sequence)
(check-type chunk-size (integer 1))

(etypecase sequence
;; Since lists have O(N) access time, we iterate through manually,
;; collecting each chunk as we pass through it. Using SUBSEQ would
;; be O(N^2).
(list (loop :while sequence
:collect
(loop :repeat chunk-size
:while sequence
:collect (pop sequence))))

;; For other sequences like strings or arrays, we can simply chunk
;; by repeated SUBSEQs.
(sequence (loop :with len := (length sequence)
:for i :below len :by chunk-size
:collect (subseq sequence i (min len (+ chunk-size i)))))))


(defun subseq- (seq &optional (start nil) (end nil))
"Like SUBSEQ, except it supports negative indices."
(if (not start)
Expand Down Expand Up @@ -766,7 +788,7 @@ PROGN."
dosublists enumerate flatten hash-table-alist
hash-table-key-exists-p hash-table-keys hash-table-values if-let
iota looping make-keyword mkstr mulf ncycle repeat
string-ends-with-p string-starts-with-p subseq- symb void when-let
when-let* while with-gensyms with-unique-names)))
string-ends-with-p string-starts-with-p subdivide subseq- symb void
when-let when-let* while with-gensyms with-unique-names)))

;;;; END OF quickutils.lisp ;;;;

0 comments on commit e02a6f6

Please sign in to comment.