MCPcopy Create free account
hub / github.com/apache/fory / run_benchmark

Function run_benchmark

benchmarks/python/fory_benchmark.py:473–502  ·  view source on GitHub ↗

Run a benchmark and return timing statistics Args: func: Function to benchmark *args: Arguments to pass to func warmup: Number of warmup iterations iterations: Number of measurement iterations repeat: Number of times to repeat each measurement num

(func, *args, warmup=3, iterations=20, repeat=5, number=10000)

Source from the content-addressed store, hash-verified

471
472
473def run_benchmark(func, *args, warmup=3, iterations=20, repeat=5, number=10000):
474 """Run a benchmark and return timing statistics
475
476 Args:
477 func: Function to benchmark
478 *args: Arguments to pass to func
479 warmup: Number of warmup iterations
480 iterations: Number of measurement iterations
481 repeat: Number of times to repeat each measurement
482 number: Number of times to call func per measurement (inner loop)
483
484 Returns:
485 (mean_time_per_call, stdev_time_per_call)
486 """
487 # Warmup
488 for _ in range(warmup):
489 for _ in range(number):
490 func(*args)
491
492 # Benchmark - run func 'number' times per measurement
493 times = []
494 for _ in range(iterations):
495 timer = timeit.Timer(lambda: func(*args))
496 iteration_times = timer.repeat(repeat=repeat, number=number)
497 # Convert total time to time per call
498 times.extend([t / number for t in iteration_times])
499
500 mean = statistics.mean(times)
501 stdev = statistics.stdev(times) if len(times) > 1 else 0
502 return mean, stdev
503
504
505def format_time(seconds):

Callers 1

micro_benchmarkFunction · 0.70

Calls 3

funcFunction · 0.85
extendMethod · 0.80
repeatMethod · 0.45

Tested by

no test coverage detected