Spaces:
Sleeping
Sleeping
File size: 4,532 Bytes
57ba219 40685b6 57ba219 40685b6 fc2520f 40685b6 d185e7b 66e0c01 40685b6 d185e7b 40685b6 d185e7b 1c47f6b 40685b6 57ba219 1c47f6b 57ba219 1c47f6b 40685b6 1c47f6b 57ba219 1c47f6b 40685b6 d185e7b 1c47f6b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
import httpx
import asyncio
import json
import time
# Define the API endpoint
url = "https://unicone-studio-search.hf.space/api/search"
# Define the search queries you want to test
test_queries = [
{"query": "Here She Is"},
{"query": "my py"},
{"query": "ahoh girl"},
{"query": "yarian"},
{"query": "grand blue"},
{"query": "Summertime"},
{"query": "yariyan 203"},
{"query": "Wahlberg Baigan and the Magic of Darkness"}, # Intentional typo to test fuzzy matching
# Additional misspelled and errored queries
{"query": "my pi"},
{"query": "aho gir"},
{"query": "yaariyan"},
{"query": "grand ble"},
{"query": "non exsitent title"},
{"query": "yariyan 20"},
{"query": "My spay"},
# Misspellings with slight variations
{"query": "yariiyn"},
{"query": "goand blue"},
{"query": "grnd blue"},
{"query": "aho grl"},
{"query": "yaariyan 2023"},
{"query": "my pye"},
# Variations in spacing and formatting
{"query": "my py"},
{"query": "aho girl"},
{"query": " yarian"},
{"query": "grandblue"},
{"query": " non-existent title"},
{"query": "yariyan203"},
{"query": "My spey"},
# More complex misspellings and typos
{"query": "ma py"},
{"query": "aho girrl"},
{"query": "yarran"},
{"query": "grnd blu"},
{"query": "nonxistent title"},
{"query": "yariyan 2-3"},
{"query": "Mey spey"},
# Phonetic errors and similar sounding words
{"query": "my pie"},
{"query": "aho girl"},
{"query": "yariyan"},
{"query": "grand bluee"},
{"query": "noe existent title"},
{"query": "yarryan"},
{"query": "Mai spay"},
# Common typographical errors
{"query": "myy py"},
{"query": "aho giirl"},
{"query": "yaaryan"},
{"query": "grand ble"},
{"query": "non existant title"},
{"query": "yarian 203"},
{"query": "My speay"},
# Random and varied input
{"query": "py my"},
{"query": "giri aho"},
{"query": "yariiian"},
{"query": "blue grand"},
{"query": "existant non title"},
{"query": "203 yariyan"},
{"query": "spey my"},
# Edge cases
{"query": " "},
{"query": "!@#$%^&*()"},
{"query": "123456"},
{"query": "aaaaaaa"},
{"query": "zzzzzzz"},
{"query": " "},
{"query": " "},
]
async def fetch_results(client, query):
start_time = time.time() # Start timing
try:
response = await client.post(url, json=query)
response.raise_for_status() # Raise an error for HTTP error responses
results = response.json()
duration = time.time() - start_time # End timing
return query['query'], results, duration
except httpx.HTTPStatusError as e:
duration = time.time() - start_time
return query['query'], f"Failed with status code {e.response.status_code}: {e.response.text}", duration
except Exception as e:
duration = time.time() - start_time
return query['query'], str(e), duration
async def stress_test_api(num_times):
async with httpx.AsyncClient() as client:
all_results = []
total_start_time = time.time() # Start timing for stress test
for _ in range(num_times):
queries = test_queries[:] # Create a copy of the test queries
tasks = [fetch_results(client, query) for query in queries]
results = await asyncio.gather(*tasks)
all_results.extend(results) # Collect all results
total_duration = time.time() - total_start_time
# Write results to a file
with open('test_results.json', 'w') as f:
json.dump({
'total_requests': num_times * len(test_queries),
'total_time_seconds': total_duration,
'average_request_time_seconds': total_duration / (num_times * len(test_queries)),
'results': [
{
'query': query,
'result': result,
'duration_seconds': duration
}
for query, result, duration in all_results
]
}, f, indent=4)
print(f"Stress Test Completed: {num_times * len(test_queries)} requests in {total_duration:.2f} seconds")
print(f"Average Request Time: {total_duration / (num_times * len(test_queries)):.2f} seconds")
if __name__ == "__main__":
num_times = 1
asyncio.run(stress_test_api(num_times))
|