コード例 #1
0
        static async Task Main(string[] args)
        {
            using var channel = GrpcChannel.ForAddress("https://localhost:4001");
            var clinet  = new WeatherForecasts.WeatherForecastsClient(channel);
            var results = await clinet.GetWeatherForecastsAsync(new GetWeatherForecastsRequest { ReturnCount = 100 });

            var table = new ConsoleTable("Date", "Temperature in C", "Summary");

            foreach (var bench in results.Forecasts)
            {
                table.AddRow(bench.Date, bench.TemperatureC, bench.Summary);
            }
            table.Write(Format.Default);
            Console.ReadLine();
        }
コード例 #2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            var returnCount = 10000;
            var benchMarks  = new List <BenchMarks>();

            while (!stoppingToken.IsCancellationRequested)
            {
                _stopwatch.Start();
                var jsonForecasts = await _httpClient.GetFromJsonAsync <WeatherForecastViewModel[]>("/weatherforecast?returnCount=" + returnCount);

                benchMarks.Add(_benchMarks("WebAPI", _stopwatch));
                _stopwatch.Reset();

                _stopwatch.Start();
                var grpcForecastsMet3 = (await _weatherForecastsClientNet3.GetWeatherForecastsAsync(new GetWeatherForecastsRequest {
                    ReturnCount = returnCount
                })).Forecasts;
                benchMarks.Add(_benchMarks("Grpc Net 3.1", _stopwatch));
                _stopwatch.Reset();

                _stopwatch.Start();
                var grpcForecastsNet5 = (await _weatherForecastsClientNet5.GetWeatherForecastsAsync(new GetWeatherForecastsRequest {
                    ReturnCount = returnCount
                })).Forecasts;
                benchMarks.Add(_benchMarks("Grpc Net 5", _stopwatch));
                _stopwatch.Reset();

                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                var table = new ConsoleTable("Client", "Data Size (kilobytes)", "Network Time (seconds)", "Deserialization Time (seconds)");
                foreach (var bench in benchMarks)
                {
                    table.AddRow(bench.Client, bench.DataSize, bench.NetworkTime, bench.DeserializationTime);
                }
                table.Write(Format.Minimal);
                Console.Read();
            }
        }