Created
November 2, 2019 02:23
-
-
Save lachlan-eagling/1b386f6b7c38c018aa1993ad7eb7b4c1 to your computer and use it in GitHub Desktop.
Blog - Performance Profiling - Fibonacci Profile
This file contains hidden or 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 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