This is an example how to write your own time measuring decorator.

import datetime
from numpy.random import rand

class time_decorator:

    def __init__(self, f):
        self.f = f
        print(f"Time decorator for {self.f.__name__} created")

    def __call__(self, *args, **kwargs):
        start =
        result = self.f(*args, **kwargs)
        duration = - start
        print(f"Duration of {self.f.__name__} function call was {duration}.")
        return result

def sum_of_random_numbers(n):
  random_numbers = rand(n)
  return sum(random_numbers)
Time decorator for sum_of_random_numbers created
Duration of sum_of_random_numbers function call was 0:00:01.092953.


Original Gist:

Try it in Colab: