Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions benchmark_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import json
import time
from pathlib import Path

Expand Down Expand Up @@ -84,3 +85,26 @@ async def _timeit_async_helper(fn, iterations: int) -> float:
start = time.perf_counter()
await fn(iterations)
return time.perf_counter() - start


def _write_benchmark_results(
result_file: Path,
py_vers,
tested_method: str,
iterations: int,
t_boto: float,
t_custom: float,
) -> dict[str, float | int | str]:
"""Build and persist common benchmark result payloads."""
results = {
"python_version": f"{py_vers.major}.{py_vers.minor}",
"tested_method": tested_method,
"iterations": iterations,
"boto_total": t_boto,
"signurlarity_total": t_custom,
"boto_ops": iterations / t_boto,
"signurlarity_ops": iterations / t_custom,
"speedup": t_boto / t_custom,
}
result_file.write_text(json.dumps(results, indent=2))
return results
192 changes: 81 additions & 111 deletions benchmark_tests/test_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pytest
from botocore.client import Config

from conftest import _timeit
from conftest import _timeit, _write_benchmark_results
from signurlarity import Client


Expand Down Expand Up @@ -87,19 +87,16 @@ def run_light(n: int):
t_custom = _timeit(run_light, iterations)

light_client.close()
results = {
"python_version": f"{py_vers.major}.{py_vers.minor}",
"tested_method": "generate_presigned_post_sync",
"iterations": iterations,
"boto_total": t_boto,
"signurlarity_total": t_custom,
"boto_ops": iterations / t_boto,
"signurlarity_ops": iterations / t_custom,
"speedup": t_boto / t_custom,
}
results = _write_benchmark_results(
result_file,
py_vers,
"generate_presigned_post_sync",
iterations,
t_boto,
t_custom,
)

print(results)
result_file.write_text(json.dumps(results, indent=2))


def test_generate_presigned_url_perf_sync(rustfs_server, test_results_dir):
Expand Down Expand Up @@ -165,19 +162,16 @@ def run_custom(n: int):
t_custom = _timeit(run_custom, iterations)

light_client.close()
results = {
"python_version": f"{py_vers.major}.{py_vers.minor}",
"tested_method": "generate_presigned_url_sync",
"iterations": iterations,
"boto_total": t_boto,
"signurlarity_total": t_custom,
"boto_ops": iterations / t_boto,
"signurlarity_ops": iterations / t_custom,
"speedup": t_boto / t_custom,
}
results = _write_benchmark_results(
result_file,
py_vers,
"generate_presigned_url_sync",
iterations,
t_boto,
t_custom,
)

print(results)
result_file.write_text(json.dumps(results, indent=2))


def test_head_bucket_perf_sync(rustfs_server, test_results_dir):
Expand Down Expand Up @@ -222,18 +216,15 @@ def run_custom(n: int):
t_custom = _timeit(run_custom, iterations)

light_client.close()
results = {
"python_version": f"{py_vers.major}.{py_vers.minor}",
"tested_method": "head_bucket_sync",
"iterations": iterations,
"boto_total": t_boto,
"signurlarity_total": t_custom,
"boto_ops": iterations / t_boto,
"signurlarity_ops": iterations / t_custom,
"speedup": t_boto / t_custom,
}
results = _write_benchmark_results(
result_file,
py_vers,
"head_bucket_sync",
iterations,
t_boto,
t_custom,
)

result_file.write_text(json.dumps(results, indent=2))


def test_head_object_perf_sync(rustfs_server, test_results_dir):
Expand Down Expand Up @@ -282,16 +273,14 @@ def run_custom(n: int):
t_custom = _timeit(run_custom, iterations)

light_client.close()
results = {
"python_version": f"{py_vers.major}.{py_vers.minor}",
"tested_method": "head_object_sync",
"iterations": iterations,
"boto_total": t_boto,
"signurlarity_total": t_custom,
"boto_ops": iterations / t_boto,
"signurlarity_ops": iterations / t_custom,
"speedup": t_boto / t_custom,
}
results = _write_benchmark_results(
result_file,
py_vers,
"head_object_sync",
iterations,
t_boto,
t_custom,
)

# Informational output
print("\n" + "=" * 60)
Expand All @@ -311,7 +300,6 @@ def run_custom(n: int):
else:
print(f"boto3 is {1 / speedup:.2f}x faster")

result_file.write_text(json.dumps(results, indent=2))

print("=" * 60)

Expand Down Expand Up @@ -360,16 +348,14 @@ def run_custom(n: int):
t_custom = _timeit(run_custom, iterations)

light_client.close()
results = {
"python_version": f"{py_vers.major}.{py_vers.minor}",
"tested_method": "create_bucket_sync",
"iterations": iterations,
"boto_total": t_boto,
"signurlarity_total": t_custom,
"boto_ops": iterations / t_boto,
"signurlarity_ops": iterations / t_custom,
"speedup": t_boto / t_custom,
}
results = _write_benchmark_results(
result_file,
py_vers,
"create_bucket_sync",
iterations,
t_boto,
t_custom,
)

# Informational output
print("\n" + "=" * 60)
Expand All @@ -389,7 +375,6 @@ def run_custom(n: int):
else:
print(f"boto3 is {1 / speedup:.2f}x faster")

result_file.write_text(json.dumps(results, indent=2))

print("=" * 60)

Expand Down Expand Up @@ -453,16 +438,14 @@ def run_custom(n: int):
t_custom = _timeit(run_custom, iterations)

light_client.close()
results = {
"python_version": f"{py_vers.major}.{py_vers.minor}",
"tested_method": "delete_objects_sync",
"iterations": iterations,
"boto_total": t_boto,
"signurlarity_total": t_custom,
"boto_ops": iterations / t_boto,
"signurlarity_ops": iterations / t_custom,
"speedup": t_boto / t_custom,
}
results = _write_benchmark_results(
result_file,
py_vers,
"delete_objects_sync",
iterations,
t_boto,
t_custom,
)

print("\n" + "=" * 60)
print("DELETE OBJECTS BENCHMARK")
Expand All @@ -481,7 +464,6 @@ def run_custom(n: int):
else:
print(f"boto3 is {1 / speedup:.2f}x faster")

result_file.write_text(json.dumps(results, indent=2))

print("=" * 60)

Expand Down Expand Up @@ -534,16 +516,14 @@ def run_custom(n: int):
t_custom = _timeit(run_custom, iterations)

light_client.close()
results = {
"python_version": f"{py_vers.major}.{py_vers.minor}",
"tested_method": "put_object_sync",
"iterations": iterations,
"boto_total": t_boto,
"signurlarity_total": t_custom,
"boto_ops": iterations / t_boto,
"signurlarity_ops": iterations / t_custom,
"speedup": t_boto / t_custom,
}
results = _write_benchmark_results(
result_file,
py_vers,
"put_object_sync",
iterations,
t_boto,
t_custom,
)

print("\n" + "=" * 60)
print("PUT OBJECT BENCHMARK")
Expand All @@ -562,7 +542,6 @@ def run_custom(n: int):
else:
print(f"boto3 is {1 / speedup:.2f}x faster")

result_file.write_text(json.dumps(results, indent=2))
print("=" * 60)


Expand Down Expand Up @@ -606,16 +585,14 @@ def run_custom(n: int):
t_custom = _timeit(run_custom, iterations)

light_client.close()
results = {
"python_version": f"{py_vers.major}.{py_vers.minor}",
"tested_method": "list_objects_sync",
"iterations": iterations,
"boto_total": t_boto,
"signurlarity_total": t_custom,
"boto_ops": iterations / t_boto,
"signurlarity_ops": iterations / t_custom,
"speedup": t_boto / t_custom,
}
results = _write_benchmark_results(
result_file,
py_vers,
"list_objects_sync",
iterations,
t_boto,
t_custom,
)

print("\n" + "=" * 60)
print("LIST OBJECTS BENCHMARK")
Expand All @@ -634,7 +611,6 @@ def run_custom(n: int):
else:
print(f"boto3 is {1 / speedup:.2f}x faster")

result_file.write_text(json.dumps(results, indent=2))
print("=" * 60)


Expand Down Expand Up @@ -694,16 +670,14 @@ def run_custom(n: int):
t_custom = _timeit(run_custom, iterations)

light_client.close()
results = {
"python_version": f"{py_vers.major}.{py_vers.minor}",
"tested_method": "copy_object_sync",
"iterations": iterations,
"boto_total": t_boto,
"signurlarity_total": t_custom,
"boto_ops": iterations / t_boto,
"signurlarity_ops": iterations / t_custom,
"speedup": t_boto / t_custom,
}
results = _write_benchmark_results(
result_file,
py_vers,
"copy_object_sync",
iterations,
t_boto,
t_custom,
)

print("\n" + "=" * 60)
print("COPY OBJECT BENCHMARK")
Expand All @@ -722,7 +696,6 @@ def run_custom(n: int):
else:
print(f"boto3 is {1 / speedup:.2f}x faster")

result_file.write_text(json.dumps(results, indent=2))
print("=" * 60)


Expand Down Expand Up @@ -783,16 +756,14 @@ def run_custom(n: int):
os.unlink(tmp_path)
light_client.close()

results = {
"python_version": f"{py_vers.major}.{py_vers.minor}",
"tested_method": "upload_file_sync",
"iterations": iterations,
"boto_total": t_boto,
"signurlarity_total": t_custom,
"boto_ops": iterations / t_boto,
"signurlarity_ops": iterations / t_custom,
"speedup": t_boto / t_custom,
}
results = _write_benchmark_results(
result_file,
py_vers,
"upload_file_sync",
iterations,
t_boto,
t_custom,
)

print("\n" + "=" * 60)
print("UPLOAD FILE BENCHMARK")
Expand All @@ -811,5 +782,4 @@ def run_custom(n: int):
else:
print(f"boto3 is {1 / speedup:.2f}x faster")

result_file.write_text(json.dumps(results, indent=2))
print("=" * 60)
Loading