浏览代码

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 年之前
父节点
当前提交
879d7c48b9
共有 1 个文件被更改,包括 6 次插入1 次删除
  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').")
     var rpc: RPC = .get
 
+    @Option(help: "How many RPCs to do.")
+    var iterations: Int = 1
+
     @Argument(help: "Message to echo")
     var message: String
 
@@ -98,7 +101,9 @@ struct Echo: ParsableCommand {
         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)
+      }
     }
   }
 }