-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (55 loc) · 1.26 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import "fmt"
import "math/rand"
import "time"
import "ring"
var done = make(chan int)
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 {}
}
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
}
func main() {
ring := ring.New(1024)
ring.WriteString("test")
ring.WriteString("")
fmt.Println(ring)
fmt.Println(ring.NextString())
fmt.Println(ring.NextString())
fmt.Println(ring.NextString())
ring.WriteString("xxx")
fmt.Println(ring.NextString())
go ping(ring, 1000000)
go pong(ring)
<-done
/*
for i := 0; true; i++ {
//fmt.Println("data", i)
pad := rand.Intn(10);
err := ring.WriteString(fmt.Sprintf("data %.*d", pad, i))
if err != nil {
fmt.Println("Error at ", i, err)
break
}
}
*/
}