Skip to content
Open
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
31 changes: 24 additions & 7 deletions scripts/benchmark/benchmark_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import argparse
from concurrent.futures import ThreadPoolExecutor, as_completed
from datetime import datetime
from pathlib import Path

from tqdm.auto import tqdm
from util import make_request
Expand Down Expand Up @@ -123,14 +125,28 @@
else:
success.append(0)

outfile = (
output
if output
else (
f"benchmark_[num_requests={num_requests}]_[max_workers={max_workers}]_"
f"[parallel={parallel}]_[route={route}]_[timeout={timeout}].csv"
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")

results_dir = Path("benchmark") / "results"
if not results_dir.exists():
results_dir.mkdir(parents=True, exist_ok=True)

if output:
outfile = Path(output)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a check to ensure path to the outfile exists. Make the parent directories if it does not exist.

else:
filename = (
f"benchmark_[t={timestamp}]"
f"_[n={num_requests}]"
f"_[w={max_workers}]"
f"_[r={route}]"
f"_[execution_mode={'par' if parallel else 'seq'}]"
".csv"
)
)
outfile = results_dir / filename

parent_dir = outfile.parent
if not parent_dir.exists():
parent_dir.mkdir(parents=True, exist_ok=True)

with open(
outfile,
Expand All @@ -139,6 +155,7 @@
f.write("status,time\n")
f.writelines(f"{s},{t}\n" for s, t in zip(success, times, strict=False))

print(f"Results saved to: {outfile}")
print(f"Benchmark completed. Successful requests: {sum(success)} out of {len(success)}")
print(f"Average time per request: {sum(times) / len(times):.2f} seconds")
print(f"Total time taken: {sum(times):.2f} seconds")