Skip to content

Instantly share code, notes, and snippets.

@lachlan-eagling
Created November 2, 2019 02:23
Show Gist options
  • Select an option

  • Save lachlan-eagling/1b386f6b7c38c018aa1993ad7eb7b4c1 to your computer and use it in GitHub Desktop.

Select an option

Save lachlan-eagling/1b386f6b7c38c018aa1993ad7eb7b4c1 to your computer and use it in GitHub Desktop.
Blog - Performance Profiling - Fibonacci Profile
import cProfile
from random import choice
def profiler(func):
def wrapper(*args, **kwargs):
with cProfile.Profile() as pr:
result = func(*args, **kwargs)
pr.print_stats()
return result
return wrapper
@profiler
def random_greeting(greetings, name):
greeting = choice(greetings)
return f"{greeting}, {name}!"
greetings = ["Hello", "Bonjour", "Ciao", "aloha", "Здравствуйте", "Hola"]
print(random_greeting(greetings, "Lachlan"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment