Browse Source

Add an --iterations option to the Echo example (#1180)

Motivation:

For performance analysis, it can be useful to have multiple iterations of RPCs. Especially in gRPC where you may want to ignore the connection setup overhead.

Modification:

Add --iterations to Echo which does the RPC that many times.

Result:

Pretty graphs (the one below shows all allocations made by one RPC).
Johannes Weiss 4 years ago
parent
commit
879d7c48b9
1 changed files with 6 additions and 1 deletions
  1. 6 1
      Sources/Examples/Echo/Runtime/main.swift

+ 6 - 1
Sources/Examples/Echo/Runtime/main.swift

@@ -79,6 +79,9 @@ struct Echo: ParsableCommand {
     @Option(help: "RPC to call ('get', 'collect', 'expand', 'update').")
     @Option(help: "RPC to call ('get', 'collect', 'expand', 'update').")
     var rpc: RPC = .get
     var rpc: RPC = .get
 
 
+    @Option(help: "How many RPCs to do.")
+    var iterations: Int = 1
+
     @Argument(help: "Message to echo")
     @Argument(help: "Message to echo")
     var message: String
     var message: String
 
 
@@ -98,7 +101,9 @@ struct Echo: ParsableCommand {
         try! client.channel.close().wait()
         try! client.channel.close().wait()
       }
       }
 
 
-      callRPC(self.rpc, using: client, message: self.message)
+      for _ in 0 ..< self.iterations {
+        callRPC(self.rpc, using: client, message: self.message)
+      }
     }
     }
   }
   }
 }
 }