Create a gist now

Instantly share code, notes, and snippets.

Embed
Comparing daisy chain benchmark for ClojureScript core.async and go-lang
(ns daisy
(:require [cljs.core.async :refer [chan <! >!]])
(:require-macros [cljs.core.async.macros :refer [go]]))
(defn f [left right]
(go (>! left (inc (<! right)))))
(let [leftmost (chan)
rightmost (loop [n 100000 left leftmost]
(if-not (pos? n)
left
(let [right (chan)]
(f left right)
(recur (dec n) right))))]
(go (time (do
(>! rightmost 1)
(.log js/console (<! leftmost))))))
;; 100001
;; "Elapsed time: 139 msecs"
;; real 0m1.214s
;; user 0m1.074s
;; sys 0m0.162s
package main
import (
"fmt"
"time"
)
func f(left, right chan int) {
left <- 1 + <-right
}
func main() {
const n = 100000
leftmost := make(chan int)
right := leftmost
left := leftmost
for i := 0; i < n; i++ {
right = make(chan int)
go f(left, right)
left = right
}
start := time.Now()
go func(c chan int) { c <- 1 }(right)
fmt.Println(<-leftmost)
fmt.Println(time.Now().Sub(start))
}
// 100001
// 65.424608ms
// real 0m0.989s
// user 0m0.326s
// sys 0m0.661s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment