main.mx raw

   1  // How long does one wake-up cost? The lattice's synchronous rounds are exactly
   2  // this: a manager sends, a worker parked in select wakes, processes, replies.
   3  // Ten thousand round trips say whether that is microseconds (a futex wake) or
   4  // the park bound (20ms) - the difference decides whether the slice measures the
   5  // machine or the wait.
   6  package main
   7  
   8  import (
   9  	"time"
  10  )
  11  
  12  const iters = int32(2000)
  13  
  14  func worker(in chan int32, out chan int32) (closed chan struct{}) {
  15  	for {
  16  		select {
  17  		case <-closed:
  18  			return closed
  19  		case v := <-in:
  20  			out <- v
  21  		}
  22  	}
  23  }
  24  
  25  func main() {
  26  	select {
  27  	case <-shutdown:
  28  		return
  29  	default:
  30  	}
  31  	in := chan int32{}
  32  	out := chan int32{}
  33  	b := spawn(worker, in, out)
  34  	start := time.Now()
  35  	for i := int32(0); i < iters; i++ {
  36  		in <- 1
  37  		<-out
  38  	}
  39  	d := time.Since(start)
  40  	us := d.Microseconds()
  41  	println("roundtrips=", iters, "total_us=", us, "us_per_rt=", us/int64(iters))
  42  	close(b)
  43  }
  44