Last active
September 29, 2023 08:39
-
-
Save manthankool/a474bf6582d2096c98ee589a5a14bc5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import time | |
api_url=Your-API-URL | |
# Number of requests to make | |
num_requests = 100 | |
# Initialize variables for tracking successes and total time | |
success_count = 0 | |
total_time = 0 | |
# Make 100 requests to the API | |
for _ in range(num_requests): | |
# Define the request parameters | |
# Send the HTTP request | |
start_time = time.time() # Record the start time | |
response = requests.get(api_url) | |
end_time = time.time() # Record the end time | |
# Calculate the time taken for the request | |
request_time = end_time - start_time | |
# Check if the request was successful (status code 200) | |
if response.status_code == 200: | |
success_count += 1 | |
total_time += request_time | |
# Calculate the success rate | |
success_rate = (success_count / num_requests) * 100 | |
# Calculate the average time taken | |
average_time = total_time / num_requests | |
# Print the results | |
print(f"Success Rate: {success_rate:.2f}%") | |
print(f"Average Time Taken: {average_time:.2f} seconds") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment