Last active
October 1, 2015 17:17
-
-
Save bergantine/2029226 to your computer and use it in GitHub Desktop.
Time the execution of a method in Python using timeit.Timer.timeit(). #python
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
| """ | |
| Look up all Users associated with a particular badge. | |
| """ | |
| import timeit | |
| s = """\ | |
| from profiles.models import Badge, UserProfile | |
| badges = Badge.objects.all().only('name') | |
| for b in badges: | |
| print b.name | |
| print UserProfile.objects.filter(badges=b).count() | |
| """ | |
| timeit.Timer(stmt=s).timeit(number=1) | |
| # Executes in 0.0585939884185791 seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment