MCPcopy Create free account
hub / github.com/0x676e67/wreq-python / run_threaded_tests

Function run_threaded_tests

benchmark/bench.py:165–217  ·  view source on GitHub ↗
(packages, url, requests_number, threads)

Source from the content-addressed store, hash-verified

163
164
165def run_threaded_tests(packages, url, requests_number, threads):
166 results = []
167 for name, session_class in packages:
168 # Test with session
169 start = time.perf_counter()
170 cpu_start = time.process_time()
171 with ThreadPoolExecutor(threads) as executor:
172 futures = [
173 executor.submit(
174 session_get_test, session_class, url, requests_number // threads
175 )
176 for _ in range(threads)
177 ]
178 for f in as_completed(futures):
179 f.result()
180 dur = round(time.perf_counter() - start, 2)
181 cpu_dur = round(time.process_time() - cpu_start, 2)
182 results.append(
183 {
184 "name": name,
185 "session": "Threaded-Session",
186 "threads": threads,
187 "size": url.split("/")[-1],
188 "time": dur,
189 "cpu_time": cpu_dur,
190 }
191 )
192
193 # Test without session
194 start = time.perf_counter()
195 cpu_start = time.process_time()
196 with ThreadPoolExecutor(threads) as executor:
197 futures = [
198 executor.submit(
199 non_session_get_test, session_class, url, requests_number // threads
200 )
201 for _ in range(threads)
202 ]
203 for f in as_completed(futures):
204 f.result()
205 dur = round(time.perf_counter() - start, 2)
206 cpu_dur = round(time.process_time() - cpu_start, 2)
207 results.append(
208 {
209 "name": name,
210 "session": "Threaded-NonSession",
211 "threads": threads,
212 "size": url.split("/")[-1],
213 "time": dur,
214 "cpu_time": cpu_dur,
215 }
216 )
217 return results
218
219
220def run_async_tests(async_packages, url, requests_number):

Callers 1

mainFunction · 0.85

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected