Created
July 29, 2022 14:35
-
-
Save kasperjunge/f3f8299650aa315542cc35ccf3ee1dbf to your computer and use it in GitHub Desktop.
Measure function speed πββοΈ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import statistics | |
from typing import Callable, Any, Tuple | |
def time_function(func: Callable, func_input: Any, n_runs: int) -> Tuple[float]: | |
times = [] | |
for _ in range(n_runs): | |
start = time.perf_counter() | |
func(func_input) | |
times.append(time.perf_counter() - start) | |
std = statistics.stdev(times) | |
mean = statistics.mean(times) | |
return mean, std | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment