Skip to content

Instantly share code, notes, and snippets.

@SerhiiKozachenko
Forked from lnostdal/upmap.clj
Created July 13, 2024 16:58
Show Gist options
  • Save SerhiiKozachenko/52874430dc753b53455775d1b3374b94 to your computer and use it in GitHub Desktop.
Save SerhiiKozachenko/52874430dc753b53455775d1b3374b94 to your computer and use it in GitHub Desktop.
Clojure unordered concurrency test: MAP vs. PMAP vs. UPMAP
;; www.Quanto.ga
;;
;; cp/upmap is from https://github.com/TheClimateCorporation/claypoole
quantataraxia.core> (do
(println "MAP:")
(println (time (doall (map (fn [x] (Thread/sleep x) x)
(range 500 50 -9)))))
(println "PMAP:")
(println (time (doall (pmap (fn [x] (Thread/sleep x) x)
(range 500 50 -9)))))
(println "UPMAP:")
(println (time (doall (cp/upmap :builtin (fn [x] (Thread/sleep x) x)
(range 500 50 -9))))))
MAP:
"Elapsed time: 13981.001996 msecs"
(500 491 482 473 464 455 446 437 428 419 410 401 392 383 374 365 356 347 338 329 320 311 302 293 284 275 266 257 248 239 230 221 212 203 194 185 176 167 158 149 140 131 122 113 104 95 86 77 68 59)
PMAP:
"Elapsed time: 712.533637 msecs"
(500 491 482 473 464 455 446 437 428 419 410 401 392 383 374 365 356 347 338 329 320 311 302 293 284 275 266 257 248 239 230 221 212 203 194 185 176 167 158 149 140 131 122 113 104 95 86 77 68 59)
UPMAP:
"Elapsed time: 500.459954 msecs"
(59 68 77 86 95 104 113 122 131 140 149 158 167 176 185 194 203 212 221 230 239 248 257 266 275 284 293 302 311 320 329 338 347 356 365 374 383 392 401 410 419 428 437 446 455 464 473 482 491 500)
nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment