From abd63a7fad65a7e1d2c0bd985c20dfd5a0876252 Mon Sep 17 00:00:00 2001 From: marcsello Date: Fri, 23 Oct 2020 16:24:28 +0200 Subject: [PATCH] Added sorting --- benchmark3.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/benchmark3.py b/benchmark3.py index 395527f..db8666f 100644 --- a/benchmark3.py +++ b/benchmark3.py @@ -130,7 +130,10 @@ def run_benchmark(num_workers: int, timeout: float, filename: str): assert count_requests_completed == len(all_requests_completed) - return all_requests_completed + final_sorted_results = list(all_requests_completed.values()) + final_sorted_results.sort(key=lambda a: a.upload_started) # sort by upload start time + + return final_sorted_results def csv_time_format(timestamp: Optional[float]) -> Optional[str]: @@ -148,7 +151,7 @@ def write_results(results, file_handle): ['id', 'http_start_time', 'http_complete_time', 'status_code', 'mqtt_arrive_time', 'latency', 'rtt'] ) - for result in results.values(): + for result in results: latency = (result.alert_arrived - result.upload_finished) * 1000 if result.alert_arrived else None rtt = (result.alert_arrived - result.upload_started) * 1000 if result.alert_arrived else None @@ -233,7 +236,7 @@ def main(): print("Waiting for inflight MQTT messages to arrive...") # Wait for inflight messages for a little - total_successful_uploads = len([req for req in benchmark_results.values() if req.upload_status_code == 200]) + total_successful_uploads = len([req for req in benchmark_results if req.upload_status_code == 200]) all_arrived = False waiting_started = time.time() for _ in range(int(args.inflight_timeout * 1000)): @@ -268,8 +271,8 @@ def main(): total_answered += 1 # print some mini statistics - total_runtime = max(benchmark_results.values(), key=lambda a: a.upload_finished).upload_finished - \ - min(benchmark_results.values(), key=lambda a: a.upload_started).upload_started + total_runtime = max(benchmark_results, key=lambda a: a.upload_finished).upload_finished - \ + min(benchmark_results, key=lambda a: a.upload_started).upload_started print( f"{len(benchmark_results)} requests completed: {total_successful_uploads} successfully uploaded and {total_answered} answered"