Last active
December 22, 2015 22:49
-
-
Save swannodette/6542719 to your computer and use it in GitHub Desktop.
Comparing daisy chain benchmark for ClojureScript core.async and go-lang
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
(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 |
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
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