Skip to content

Instantly share code, notes, and snippets.

@chrisdavies
Created February 11, 2014 15:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisdavies/8937211 to your computer and use it in GitHub Desktop.
Save chrisdavies/8937211 to your computer and use it in GitHub Desktop.
A test of a million communications between channels.
import (
"fmt"
)
func main() {
num := 1000000
tots := 0
bg_chan := make(chan int, num)
fg_chan := make(chan int, num)
go func() {
for i := 0; i < num; i++ {
bg_chan <- i
<-fg_chan
}
}()
for i := 0; i < num; i++ {
tots += <- bg_chan
fg_chan <- i
}
fmt.Println(tots)
}
fn main() {
let (to_port, to_chan): (Port<int>, Chan<int>) = Chan::new();
let (from_port, from_chan): (Port<int>, Chan<int>) = Chan::new();
let mut tots: int = 0;
let num = 1000000;
do spawn {
for _ in range(0, num) {
from_chan.send(to_port.recv());
}
}
for i in range(0, num) {
to_chan.send(i);
tots += from_port.recv();
}
println(tots.to_str());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment