from typing import Callable
from typing import Any
import time


def _pytimed(callback: Callable[..., None], *args: Any, **kwargs: Any):
  """Call the given callback and return time in nanoseconds as result."""
  start_time = time.monotonic_ns()
  results = callback(*args, **kwargs)
  end_time = time.monotonic_ns()
  duration = (end_time - start_time)
  return duration