Last active
April 28, 2020 18:25
-
-
Save susmithagudapati/365b14a1f9824eba7ee2f6ab15773f9e 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
# takes more time because it loads the whole model object into Python memory | |
%timeit upcs = [product.upc for product in Product.objects.all()] | |
3.91 ms ± 131 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) | |
# faster than the above code because an SQL expression executes this | |
%timeit Product.objects.values_list('upc', flat=True) | |
32.3 µs ± 1.12 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment