private async Task ReadBenchmark(DocumentClient client, string replicaType, bool final = false) { Stopwatch stopwatch = new Stopwatch(); string region = Helpers.ParseEndpoint(client.ReadEndpoint); FeedOptions feedOptions = new FeedOptions { PartitionKey = new PartitionKey(PartitionKeyValue) }; string sql = "SELECT c._self FROM c"; var items = client.CreateDocumentQuery(containerUri, sql, feedOptions).ToList(); int i = 0; int total = items.Count; List <Result> result = new List <Result>(); Console.WriteLine(); Console.WriteLine($"Test {total} reads against {replicaType} account in {region} from West US 2\r\nPress any key to continue\r\n..."); Console.ReadKey(true); RequestOptions requestOptions = new RequestOptions { PartitionKey = new PartitionKey(PartitionKeyValue) }; foreach (Document item in items) { stopwatch.Start(); ResourceResponse <Document> response = await client.ReadDocumentAsync(item.SelfLink, requestOptions); stopwatch.Stop(); Console.WriteLine($"Read {i} of {total}, region: {region}, Latency: {stopwatch.ElapsedMilliseconds} ms, Request Charge: {response.RequestCharge} RUs"); result.Add(new Result(stopwatch.ElapsedMilliseconds, response.RequestCharge)); i++; stopwatch.Reset(); } //Average at 99th Percentile string _latency = Math.Round(result.OrderBy(o => o.Latency).Take(99).Average(o => o.Latency), 0).ToString(); string _ru = Math.Round(result.OrderBy(o => o.Latency).Take(99).Average(o => o.RU)).ToString(); results.Add(new ResultData { Test = $"Test {replicaType}", AvgLatency = _latency, AvgRU = _ru }); Console.WriteLine(); Console.WriteLine("Summary"); Console.WriteLine("-----------------------------------------------------------------------------------------------------"); Console.WriteLine($"Test {total} reads against {replicaType} account in {region}"); Console.WriteLine(); Console.WriteLine($"Average Latency:\t{_latency} ms"); Console.WriteLine($"Average Request Units:\t{_ru} RUs"); Console.WriteLine(); Console.WriteLine("Press any key to continue..."); Console.ReadKey(true); if (final) { Console.WriteLine(); Console.WriteLine("Summary"); Console.WriteLine("-----------------------------------------------------------------------------------------------------"); foreach (ResultData r in results) { Console.WriteLine($"{r.Test}\tAvg Latency: {r.AvgLatency} ms\tAverage RU: {r.AvgRU}"); } Console.WriteLine(); Console.WriteLine($"Test concluded. Press any key to continue\r\n..."); Console.ReadKey(true); } }