From aa976543ce46d394a635e1242d0046716d34da5b Mon Sep 17 00:00:00 2001 From: Predrag Gruevski Date: Tue, 26 Nov 2024 21:50:32 +0000 Subject: [PATCH] Delint benchmark files. --- python/bench/json_serialization.py | 41 +++++++++++++++++------ python/bench/tracing_client_bench.py | 2 +- python/bench/tracing_client_via_pyo3.py | 4 +-- python/bench/tracing_rust_client_bench.py | 1 - 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/python/bench/json_serialization.py b/python/bench/json_serialization.py index de842a06e..d81480f79 100644 --- a/python/bench/json_serialization.py +++ b/python/bench/json_serialization.py @@ -1,9 +1,9 @@ -import time import statistics +import time +import zlib from concurrent.futures import ThreadPoolExecutor -import threading + import orjson -import zlib def create_json_with_large_array(length): @@ -62,7 +62,9 @@ def serialize_parallel(data): def serialize_sequential_gz(data): - """Serialize data sequentially and compress using zlib with adjustable compression level.""" + """Serialize data sequentially and compress using zlib. + + With adjustable compression level.""" compressed_data = [] for json_obj in data: serialized = orjson.dumps(json_obj) @@ -71,7 +73,9 @@ def serialize_sequential_gz(data): return compressed_data def serialize_parallel_gz(data): - """Serialize data in parallel using ThreadPoolExecutor and compress using zlib with adjustable compression level.""" + """Serialize data in parallel with zlib. + + Using ThreadPoolExecutor and zlib with adjustable compression level.""" def compress_item(json_obj): serialized = orjson.dumps(json_obj) @@ -116,11 +120,28 @@ def main(): data = [create_json_with_large_array(json_length) for _ in range(num_json_objects)] serialized_data = serialize_sequential(data) - for func in [serialize_sequential, serialize_parallel, serialize_sequential_gz, serialize_parallel_gz, gzip_sequential, gzip_parallel]: - # data = [create_json_with_large_strings(json_length) for _ in range(num_json_objects)] - - print(f"\nBenchmarking {func.__name__} with {num_json_objects} JSON objects of length {json_length}...") - results_seq = benchmark_serialization(data, func) if not func.__name__.startswith("gzip") else benchmark_serialization(serialized_data, func) + for func in [ + serialize_sequential, + serialize_parallel, + serialize_sequential_gz, + serialize_parallel_gz, + gzip_sequential, + gzip_parallel, + ]: + # data = [ + # create_json_with_large_strings(json_length) + # for _ in range(num_json_objects) + # ] + + print( + f"\nBenchmarking {func.__name__} with {num_json_objects} JSON objects " + f"of length {json_length}..." + ) + results_seq = ( + benchmark_serialization(data, func) + if not func.__name__.startswith("gzip") + else benchmark_serialization(serialized_data, func) + ) print(f"Mean time: {results_seq['mean']:.4f} seconds") print(f"Median time: {results_seq['median']:.4f} seconds") print(f"Std Dev: {results_seq['stdev']:.4f} seconds") diff --git a/python/bench/tracing_client_bench.py b/python/bench/tracing_client_bench.py index 85251f0a1..7e6d18b86 100644 --- a/python/bench/tracing_client_bench.py +++ b/python/bench/tracing_client_bench.py @@ -1,6 +1,6 @@ -from datetime import datetime, timedelta, timezone import statistics import time +from datetime import datetime, timedelta, timezone from typing import Dict, Optional from unittest.mock import Mock from uuid import uuid4 diff --git a/python/bench/tracing_client_via_pyo3.py b/python/bench/tracing_client_via_pyo3.py index f1fe0091c..cb1cd6b97 100644 --- a/python/bench/tracing_client_via_pyo3.py +++ b/python/bench/tracing_client_via_pyo3.py @@ -1,8 +1,8 @@ +import os +import time from datetime import datetime, timedelta, timezone from typing import Any, Dict from uuid import uuid4 -import time -import os from tracing_client_bench import create_run_data diff --git a/python/bench/tracing_rust_client_bench.py b/python/bench/tracing_rust_client_bench.py index dd2a98bac..6c5203d98 100644 --- a/python/bench/tracing_rust_client_bench.py +++ b/python/bench/tracing_rust_client_bench.py @@ -2,7 +2,6 @@ import statistics import time from typing import Dict -from unittest.mock import Mock from uuid import uuid4 from langsmith_pyo3 import BlockingTracingClient