Last active
April 28, 2020 18:26
-
-
Save susmithagudapati/a524a98896d56d089015e84534ca2ef9 to your computer and use it in GitHub Desktop.
This file contains 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
# slower because it loads all products into Python memory to execute 'len()' | |
%timeit len(Product.objects.all()) | |
3.47 ms ± 36 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) | |
# faster because an SQL expression executes this | |
%timeit Product.objects.count() | |
267 µs ± 7.51 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment