Skip to content

Instantly share code, notes, and snippets.

@manthankool
Last active September 29, 2023 08:39
Show Gist options
  • Save manthankool/a474bf6582d2096c98ee589a5a14bc5d to your computer and use it in GitHub Desktop.
Save manthankool/a474bf6582d2096c98ee589a5a14bc5d to your computer and use it in GitHub Desktop.
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