Skip to content

Commit

Permalink
Delint benchmark files.
Browse files Browse the repository at this point in the history
  • Loading branch information
obi1kenobi committed Nov 26, 2024
1 parent 25bba30 commit aa97654
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
41 changes: 31 additions & 10 deletions python/bench/json_serialization.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion python/bench/tracing_client_bench.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/bench/tracing_client_via_pyo3.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 0 additions & 1 deletion python/bench/tracing_rust_client_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aa97654

Please sign in to comment.