The function receives the domain portion of the URL as an argument server. I wanted this to be easy to set up, so I could move from my development system to my production system. An API key is also passed to this function so that requests can be authenticated. Finally, the arguments startand endrequired from the query string are passed and appended to the URL before making the request. The dictionary resultsuses the URLs in the list requestsas keys. For each key, I store an array of results, not a single value, because this allows me to record multiple runs for each query and get an average.
To complete my test script, I added a function run_test()and a command line whatsapp philippines number parser: Python Copy the code import argparse import random import subprocess from threading import Thread from timeit import timeit requests = [ # ... ] results = {url: [] for url in requests} def test(server, apikey, start, end): # ... def run_test(num_threads, server, apikey, start, end): threads = [Thread(target=test, args=(server, apikey, start, end)) for _ in range(num_threads)] for thread in threads: thread.start() for thread in threads: thread.join() total_sum = 0 total_n = 0 for url in sorted(results.keys()): total_sum += sum(results) total_n += len(results[url]) avg = su ... .png[/img]
2f}') avg = total_sum / total_n print(f'Total Query Average: {avg:.2f}') parser = argparse.ArgumentParser() parser.add_argument('--clients', '-c', metavar='N', type=int, default=2, help='number of concurrent clients (default: 2)') parser.add_argument('--start-date', '-s', metavar='DATE', default='2021-01-01', help='query start date (default: 2021-01-01)') parser.add_argument('--end-date', '-e', metavar='DATE', default='2021-12-31', help='query end date (default: 2021-12-31)') parser.add_argument('server', metavar='SERVER', help='server to connect to.') parser.add_argument('apikey', metavar='APIKEY', help='API key to authenticate with.') args = parser.parse_args() run_test(args.clients, args.server, args.apikey, args.start_date, args.end_date) The function run_test()launches one or more threads depending on the argument num_threads. All threads are configured to run the function test()in parallel.
To complete my test script
-
- Posts: 10
- Joined: Sun Dec 22, 2024 5:33 am