Skip to content

Instantly share code, notes, and snippets.

@dannypsnl
Created November 23, 2025 11:02
Show Gist options
  • Select an option

  • Save dannypsnl/fe2b8a7732002953a3dcbb825499a020 to your computer and use it in GitHub Desktop.

Select an option

Save dannypsnl/fe2b8a7732002953a3dcbb825499a020 to your computer and use it in GitHub Desktop.
Playing parallel threads of Racket 9
#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)))
@dannypsnl
Copy link
Author

dannypsnl commented Nov 23, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment