guile-knots/tests/parallelism.scm
Christopher Baines dc2fe732ea Make the parallel operations more continuous
Instead of batching the list items, change the batch size to a
parallelism limit and run up to that many fibers. When the processing
of one list item finishes, another will then start immediately after,
rather than when the whole batch is finished.

These changes also make the fibers-map and fibers-for-each operations
work with vectors as well as lists.
2024-12-22 12:24:49 +00:00

46 lines
952 B
Scheme

(use-modules (tests)
(fibers)
(unit-test)
(knots parallelism))
;; Test fibers-map
(run-fibers-for-tests
(lambda ()
(assert-equal
1122
(apply + (fibers-map
(lambda (i)
(* 2 i))
(iota 34))))))
;; Test fibers-batch-map with a large batch size
(run-fibers-for-tests
(lambda ()
(assert-equal
1122
(apply + (fibers-batch-map
(lambda (i)
(* 2 i))
100
(iota 34))))))
;; Test fibers-map with vectors
(run-fibers-for-tests
(lambda ()
(assert-equal
1122
(apply + (vector->list
(fibers-map
(lambda (i)
(* 2 i))
(list->vector (iota 34))))))))
;; Test fibers-for-each
(run-fibers-for-tests
(lambda ()
(fibers-for-each
(lambda (i)
(* 2 i))
(iota 34))))
(display "parallelism test finished successfully\n")