Exemple #1
0
func ping(ring *ring.Ring, count int) {
	for i := 0; i != count; i++ {
		pad := rand.Intn(100)
		//fmt.Println("ping", i)
		for ring.WriteString(fmt.Sprintf("data %.*d", pad, i)) != nil {
		}
	}
	for ring.WriteString("") != nil {
	}
}
Exemple #2
0
func pong(ring *ring.Ring) {
	count, bytes := 0, 0
	begin := time.Now()
	for {
		data := ring.NextString()
		if data == nil {
			continue
		}

		count++
		bytes += len(*data)
		//fmt.Println("Pong", count, bytes, *data)
		if len(*data) == 0 {
			break
		}
	}
	t := time.Now().Sub(begin)
	fmt.Printf("Messages: %d; Bytes: %d; Time: %v\n", count, bytes, t)
	fmt.Printf("Speed: %.3fm/us\n", float64(count)/(1000000*t.Seconds()))
	done <- 1
}