Skip to content

Instantly share code, notes, and snippets.

@divs1210
Last active November 16, 2017 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save divs1210/625422be5a3e326c991e5ced60b01c1c to your computer and use it in GitHub Desktop.
Save divs1210/625422be5a3e326c991e5ced60b01c1c to your computer and use it in GitHub Desktop.
Benchmark for functional-core-async
(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)))))))
@divs1210
Copy link
Author

divs1210 commented Nov 16, 2017

A port of this core.async example.
Taken from the mailing list (posted by user kandre).
Takes 0.5s on my machine.

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