Browse Source

restore performance from before refactor

Norwin Roosen 3 months ago
parent
commit
6e15e7518b
1 changed files with 9 additions and 14 deletions
  1. 9
    14
      main.go

+ 9
- 14
main.go View File

@@ -22,7 +22,7 @@ var cpuprofile = flag.String("cpuprofile", "", "Destination file for CPU Profile
22 22
 var image_path = flag.String("image", "", "Absolute Path to image")
23 23
 var image_offsetx = flag.Int("xoffset", 0, "Offset of posted image from left border")
24 24
 var image_offsety = flag.Int("yoffset", 0, "Offset of posted image from top border")
25
-var connections = flag.Int("connections", 10, "Number of simultaneous connections/threads. Each Thread posts a subimage")
25
+var connections = flag.Int("connections", 4, "Number of simultaneous connections. Each connection posts a subimage")
26 26
 var address = flag.String("host", "127.0.0.1:1337", "Server address")
27 27
 var runtime = flag.String("runtime", "1", "Runtime in Minutes")
28 28
 var shuffle = flag.Bool("shuffle", false, "pixel send ordering")
@@ -69,7 +69,7 @@ func main() {
69 69
 	time.Sleep(time.Minute * timer)
70 70
 }
71 71
 
72
-func bomb(messages [][]byte) {
72
+func bomb(messages []byte) {
73 73
 	conn, err := net.Dial("tcp", *address)
74 74
 	if err != nil {
75 75
 		log.Fatal(err)
@@ -79,11 +79,9 @@ func bomb(messages [][]byte) {
79 79
 
80 80
 	// Start bombardement
81 81
 	for {
82
-		for _, message := range messages {
83
-			_, err := conn.Write(message)
84
-			if err != nil {
85
-				log.Fatal(err)
86
-			}
82
+		_, err := conn.Write(messages)
83
+		if err != nil {
84
+			log.Fatal(err)
87 85
 		}
88 86
 	}
89 87
 }
@@ -129,18 +127,15 @@ func genCommands(img image.Image, offset_x, offset_y int) (commands [][]byte) {
129 127
 }
130 128
 
131 129
 // Splits messages into equally sized chunks
132
-func chunkCommands(commands [][]byte, numChunks int) [][][]byte {
133
-	chunks := make([][][]byte, numChunks)
130
+func chunkCommands(commands [][]byte, numChunks int) [][]byte {
131
+	chunks := make([][]byte, numChunks)
134 132
 
135 133
 	chunkLength := len(commands) / numChunks
136 134
 	for i := 0; i < numChunks; i++ {
137 135
 		cmdOffset := i * chunkLength
138
-
139
-		if cmdOffset+chunkLength > len(commands) {
140
-			chunks[i] = commands[cmdOffset:]
141
-			break
136
+		for j := 0; j < chunkLength; j++ {
137
+			chunks[i] = append(chunks[i], commands[cmdOffset+j]...)
142 138
 		}
143
-		chunks[i] = commands[cmdOffset : cmdOffset+chunkLength]
144 139
 	}
145 140
 	return chunks
146 141
 }

Loading…
Cancel
Save