Skip to content

Commit

Permalink
build: Always interpret tests and reduce the number of iterations.
Browse files Browse the repository at this point in the history
With this change, tests run in 87s instead of 230s on my x86_64 laptop
when using ‘guix build -f guix.scm’.

* build-aux/guile.am (.scm.go): Set GUILE_AUTO_COMPILE=0.
* Makefile.am (TESTS_ENVIRONMENT): Pass ‘--no-auto-compile’.
* tests/basic.scm (%long-loop-iterations): New variable.
(loop-to-1e4): Rename to…
(loop-long-enough): … this.  Refer to ‘%long-loop-iterations’.
* guix.scm (guile-fibers)[arguments]: Remove.
* tests/speedup.scm: Divide by 10 the number of iterations.
  • Loading branch information
civodul committed Nov 23, 2024
1 parent 6c7347c commit c295960
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
4 changes: 3 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ TESTS += \
tests/concurrent-web-server.scm
endif

TESTS_ENVIRONMENT=top_srcdir="$(abs_top_srcdir)" ./env $(GUILE) -s
TESTS_ENVIRONMENT = \
top_srcdir="$(abs_top_srcdir)" ./env \
$(GUILE) --no-auto-compile -s

EXTRA_DIST += \
$(bin_SCRIPTS) \
Expand Down
2 changes: 1 addition & 1 deletion build-aux/guile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ EXTRA_DIST = $(SOURCES) $(NOCOMP_SOURCES)
GUILE_WARNINGS = -Wunbound-variable -Warity-mismatch -Wformat
SUFFIXES = .scm .go
.scm.go:
$(AM_V_GEN) $(top_builddir)/env \
$(AM_V_GEN) GUILE_AUTO_COMPILE=0 $(top_builddir)/env \
$(GUILE_TOOLS) compile $(GUILE_TARGET) -L "$(abs_top_srcdir)" \
$(GUILE_WARNINGS) -o "$@" "$<"
8 changes: 0 additions & 8 deletions guix.scm
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@
"texinfo" "gettext-minimal"))))
(inputs
(list (S "guile")))
(arguments
`(#:phases (modify-phases %standard-phases
(add-before 'configure 'bootstrap
(lambda _
(zero? (system* "./autogen.sh"))))
(add-before 'configure 'setenv
(lambda _
(setenv "GUILE_AUTO_COMPILE" "0"))))))
(synopsis "Lightweight concurrency facility for Guile")
(description
"Fibers is a Guile library that implements a a lightweight concurrency
Expand Down
14 changes: 11 additions & 3 deletions tests/basic.scm
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,17 @@
(assert-run-fibers-terminates (do-times 100000 (spawn-fiber (lambda () #t))) #:drain? #t)
(assert-run-fibers-terminates (do-times 100000
(spawn-fiber (lambda () #t) #:parallel? #t)) #:drain? #t)
(define (loop-to-1e4) (let lp ((i 0)) (when (< i #e1e4) (lp (1+ i)))))
(assert-run-fibers-terminates (do-times 100000 (spawn-fiber loop-to-1e4)) #:drain? #t)
(assert-run-fibers-terminates (do-times 100000 (spawn-fiber loop-to-1e4 #:parallel? #t)) #:drain? #t)

(define %long-loop-iterations
;; Number of iterations such that 'loop-long-enough' takes a while (~30s)
;; or current hardware when this file is interpreted.
#e1e3)

(define (loop-long-enough)
(let lp ((i 0)) (when (< i %long-loop-iterations) (lp (1+ i)))))

(assert-run-fibers-terminates (do-times 100000 (spawn-fiber loop-long-enough)) #:drain? #t)
(assert-run-fibers-terminates (do-times 100000 (spawn-fiber loop-long-enough #:parallel? #t)) #:drain? #t)
(assert-run-fibers-terminates (do-times 1 (spawn-fiber (lambda () (sleep 1)))) #:drain? #t)
(assert-run-fibers-terminates (do-times 10 (spawn-fiber (lambda () (sleep 1)))) #:drain? #t)
(assert-run-fibers-terminates (do-times 100 (spawn-fiber (lambda () (sleep 1)))) #:drain? #t)
Expand Down
12 changes: 6 additions & 6 deletions tests/speedup.scm
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ Set the 'FIBERS_EXPENSIVE_TESTS' environment variable to run it.~%")
(measure-speedup
(do-times 40000 (spawn-fiber (lambda () (sleep 1)) #:parallel? #t)))
(measure-speedup
(do-times 100000 (spawn-fiber (lambda () (loop-to #e1e4)) #:parallel? #t)))
(do-times 100000 (spawn-fiber (lambda () (loop-to #e1e3)) #:parallel? #t)))
(measure-speedup
(do-times 10000 (spawn-fiber (lambda () (loop-to #e1e5)) #:parallel? #t)))
(do-times 10000 (spawn-fiber (lambda () (loop-to #e1e4)) #:parallel? #t)))
(measure-speedup
(do-times 1000 (spawn-fiber (lambda () (loop-to #e1e6)) #:parallel? #t)))
(do-times 1000 (spawn-fiber (lambda () (loop-to #e1e5)) #:parallel? #t)))

(measure-speedup
(do-times 100000 (spawn-fiber (lambda () (alloc-to 4 #e1e3)) #:parallel? #t)))
(do-times 100000 (spawn-fiber (lambda () (alloc-to 4 #e1e2)) #:parallel? #t)))
(measure-speedup
(do-times 10000 (spawn-fiber (lambda () (alloc-to 4 #e1e4)) #:parallel? #t)))
(do-times 10000 (spawn-fiber (lambda () (alloc-to 4 #e1e3)) #:parallel? #t)))
(measure-speedup
(do-times 1000 (spawn-fiber (lambda () (alloc-to 4 #e1e5)) #:parallel? #t)))
(do-times 1000 (spawn-fiber (lambda () (alloc-to 4 #e1e4)) #:parallel? #t)))

0 comments on commit c295960

Please sign in to comment.