MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / benchmark

Function benchmark

benchmarks/python-performance.py:21–27  ·  view source on GitHub ↗

Benchmark a function over multiple iterations

(fn: Callable, iterations: int, **kwargs)

Source from the content-addressed store, hash-verified

19from typing import Dict, Any, Callable
20
21def benchmark(fn: Callable, iterations: int, **kwargs) -> float:
22 """Benchmark a function over multiple iterations"""
23 start = time.perf_counter()
24 for _ in range(iterations):
25 fn(**kwargs)
26 end = time.perf_counter()
27 return (end - start) * 1000 # Convert to milliseconds
28
29def is_verbose() -> bool:
30 return ('--verbose' in sys.argv) or ('-v' in sys.argv) or (os.getenv('BENCH_VERBOSE') == '1')

Callers 1

run_benchmarksFunction · 0.70

Calls 2

rangeFunction · 0.85
fnFunction · 0.85

Tested by

no test coverage detected