Skip to content

Instantly share code, notes, and snippets.

@rafacv
Created November 13, 2011 21:36
Show Gist options
  • Save rafacv/1362759 to your computer and use it in GitHub Desktop.
Save rafacv/1362759 to your computer and use it in GitHub Desktop.
Comparison between list()'s and lists' comprehension implementation.
my_list = list(range(1000000))
for i in range(100):
other_list = [elem for elem in my_list]
my_list = list(range(1000000))
for i in range(100):
other_list = list(my_list)
$ 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