Last active
November 16, 2017 09:57
-
-
Save divs1210/625422be5a3e326c991e5ced60b01c1c to your computer and use it in GitHub Desktop.
Benchmark for functional-core-async
This file contains 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
(defn event [env type val] | |
(let [rc (chan)] | |
(>! (:queue @env) | |
{:type type :val val :rc rc :time (:now @env)}) | |
(<! rc))) | |
(defn bench [] | |
(time | |
(let [n 100000 | |
env (atom {:now 0 :queue (chan)})] | |
;; car | |
(go | |
(loop [] | |
#_(println "Driving at " (:now @env)) | |
(event env :timeout 5) | |
#_(println "Parking at " (:now @env)) | |
(event env :timeout 2) | |
(when (< (:now @env) n) | |
(recur)))) | |
(loop [] | |
(let [e (<! (:queue @env)) | |
nt (+ (:val e) (:now @env))] | |
(when (< nt n) | |
(swap! env assoc :now nt) | |
(go (>! (:rc e) true)) | |
(recur))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A port of this core.async example.
Taken from the mailing list (posted by user kandre).
Takes 0.5s on my machine.