Skip to content

Instantly share code, notes, and snippets.

@kasperjunge
Created July 29, 2022 14:35
Show Gist options
  • Save kasperjunge/f3f8299650aa315542cc35ccf3ee1dbf to your computer and use it in GitHub Desktop.
Save kasperjunge/f3f8299650aa315542cc35ccf3ee1dbf to your computer and use it in GitHub Desktop.
Measure function speed πŸƒβ€β™‚οΈ
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