-
Notifications
You must be signed in to change notification settings - Fork 0
/
one.go
93 lines (81 loc) · 1.82 KB
/
one.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"fmt"
"time"
)
func main() {
defer func(t time.Time) { fmt.Printf("total took %v\n", time.Since(t)) }(time.Now())
t := time.Now()
payloads := createPayloads("hello %s, your word of the day is %s")
fmt.Printf("payload creation took %v\n", time.Since(t))
t = time.Now()
sendPayloads(payloads)
fmt.Printf("payload sending took %v\n", time.Since(t))
}
func createPayloads(message string) map[string][]string {
payloads := make(map[string][]string)
iosUsers := getIOSUsers()
androidUsers := getAndroidUsers()
words := getWords()
for i, word := range words {
payloads["ios"] = append(payloads["ios"], fmt.Sprintf(message, iosUsers[i], word))
payloads["android"] = append(payloads["android"], fmt.Sprintf(message, androidUsers[i], word))
}
return payloads
}
func getAndroidUsers() []string {
time.Sleep(500 * time.Millisecond) // database overhead
return androidUsers
}
func getIOSUsers() []string {
time.Sleep(500 * time.Millisecond) // database overhead
return iosUsers
}
func getWords() []string {
time.Sleep(500 * time.Millisecond) // database overhead
return words
}
func sendPayloads(payloads map[string][]string) {
for platform, payloads := range payloads {
for _, payload := range payloads {
switch platform {
case "ios":
time.Sleep(100 * time.Millisecond) // network overhead
fmt.Printf("apns | %s\n", payload)
case "android":
time.Sleep(100 * time.Millisecond) // network overhead
fmt.Printf("gcm | %s\n", payload)
}
}
}
}
var words = []string{
"lorem",
"ipsum",
"dolor",
"sit",
"amet",
"consectetur",
"adipiscing",
"elit",
}
var androidUsers = []string{
"Shawn",
"Cari",
"Alara",
"Poppy-Mae",
"Lennie",
"Jack",
"Amrita",
"Mylo",
}
var iosUsers = []string{
"Brooklyn",
"Fahad",
"Chardonnay",
"Callam",
"Rebekah",
"Byron",
"Rikki",
"Keyan",
}