-
Notifications
You must be signed in to change notification settings - Fork 19
Update benchmark_requests.py #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 4 commits
c7f9fca
e2471d8
df2aa4d
50cc321
5bd15b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,10 +2,15 @@ | |
|
|
||
| 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 | ||
|
|
||
| RESULTS_DIR = Path(__file__).parent / "results" | ||
| RESULTS_DIR.mkdir(exist_ok=True) | ||
|
|
||
| if __name__ == "__main__": | ||
| """Main function to benchmark the PESUAuth API. | ||
|
|
||
|
|
@@ -123,14 +128,30 @@ | |
| else: | ||
| success.append(0) | ||
|
|
||
| outfile = ( | ||
| timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") | ||
| if output: | ||
| outfile = Path(output) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can simply compute and use the results dir here, since it is not being used anywhere else. Also, no need to make it a constant. |
||
|
|
||
| outfile.parent.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| """outfile = ( | ||
| output | ||
| if output | ||
| else ( | ||
| f"benchmark_[num_requests={num_requests}]_[max_workers={max_workers}]_" | ||
| f"[parallel={parallel}]_[route={route}]_[timeout={timeout}].csv" | ||
| ) | ||
| ) | ||
| )""" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this docstring?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uhh this was old code, i thought it would be a god idea to keep this as a docstring in case a slip up happens π |
||
|
|
||
| with open( | ||
| outfile, | ||
|
|
@@ -139,6 +160,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 the following directory: {outfile}") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default path should be
benchmark/results.