MCPcopy Index your code
hub / github.com/python/cpython / benchmark

Function benchmark

Tools/ftscalingbench/ftscalingbench.py:315–336  ·  view source on GitHub ↗
(func)

Source from the content-addressed store, hash-verified

313
314
315def benchmark(func):
316 delta_one_thread = bench_one_thread(func)
317 delta_many_threads = bench_parallel(func)
318
319 speedup = delta_one_thread * len(threads) / delta_many_threads
320 if speedup >= 1:
321 factor = speedup
322 direction = "faster"
323 else:
324 factor = 1 / speedup
325 direction = "slower"
326
327 use_color = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
328 color = reset_color = ""
329 if use_color:
330 if speedup <= 1.1:
331 color = "\x1b[31m" # red
332 elif speedup < len(threads)/2:
333 color = "\x1b[33m" # yellow
334 reset_color = "\x1b[0m"
335
336 print(f"{color}{func.__name__:<25} {round(factor, 1):>4}x {direction}{reset_color}")
337
338def determine_num_threads_and_affinity():
339 if sys.platform != "linux":

Callers 1

mainFunction · 0.70

Calls 3

bench_one_threadFunction · 0.85
bench_parallelFunction · 0.85
isattyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…