Created
November 13, 2011 21:36
-
-
Save rafacv/1362759 to your computer and use it in GitHub Desktop.
Comparison between list()'s and lists' comprehension implementation.
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
my_list = list(range(1000000)) | |
for i in range(100): | |
other_list = [elem for elem in my_list] |
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
my_list = list(range(1000000)) | |
for i in range(100): | |
other_list = list(my_list) |
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
$ time python list_comprehension.py | |
real 0m17.746s | |
user 0m14.489s | |
sys 0m1.827s | |
$ time python list_function.py | |
real 0m4.266s | |
user 0m3.740s | |
sys 0m0.319s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment