Created
November 23, 2025 11:02
-
-
Save dannypsnl/fe2b8a7732002953a3dcbb825499a020 to your computer and use it in GitHub Desktop.
Playing parallel threads of Racket 9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #lang racket | |
| (define (split-list lst n) | |
| (for/list ([i (in-range 0 (length lst) n)]) | |
| (take (drop lst i) (min n (- (length lst) i))))) | |
| (define P (make-parallel-thread-pool (processor-count))) | |
| (define JOBS (split-list (range 1 10000000) 100000)) | |
| (time | |
| (define thds | |
| (for/list ([work-N JOBS]) | |
| (thread | |
| #:pool P | |
| #:keep 'results | |
| (thunk (for/sum ([i work-N]) i))))) | |
| (for/sum ([t thds]) | |
| (thread-wait t))) | |
| (time | |
| (define fts | |
| (for/list ([work-N JOBS]) | |
| (future (thunk (for/sum ([i work-N]) i))))) | |
| (for/sum ([f fts]) | |
| (touch f))) | |
| (time | |
| (for/sum ([j JOBS]) | |
| (for/sum ([i j]) i))) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cpu time: 488 real time: 59 gc time: 19
49999995000000
cpu time: 443 real time: 42 gc time: 6
49999995000000
cpu time: 194 real time: 196 gc time: 1
49999995000000
on Apple M4 Pro, 48GB