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

Function run_benchmark

benchmarks/python/benchmark.py:747–768  ·  view source on GitHub ↗
(
    func: Callable[..., Any],
    args: Tuple[Any, ...],
    *,
    warmup: int,
    iterations: int,
    repeat: int,
    number: int,
)

Source from the content-addressed store, hash-verified

745
746
747def run_benchmark(
748 func: Callable[..., Any],
749 args: Tuple[Any, ...],
750 *,
751 warmup: int,
752 iterations: int,
753 repeat: int,
754 number: int,
755) -> Tuple[float, float]:
756 for _ in range(warmup):
757 for _ in range(number):
758 func(*args)
759
760 samples: List[float] = []
761 for _ in range(iterations):
762 timer = timeit.Timer(lambda: func(*args))
763 loop_times = timer.repeat(repeat=repeat, number=number)
764 samples.extend([time_total / number for time_total in loop_times])
765
766 mean = statistics.mean(samples)
767 stdev = statistics.stdev(samples) if len(samples) > 1 else 0.0
768 return mean, stdev
769
770
771def format_time(seconds: float) -> str:

Callers 1

mainFunction · 0.70

Calls 3

funcFunction · 0.85
extendMethod · 0.80
repeatMethod · 0.45

Tested by

no test coverage detected