Created
November 1, 2013 18:11
-
-
Save mulander/7269424 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
# mulander@craig-laptop:~/art/bench$ python test.py | |
# 1.89928817749 | |
# 1.24240493774 | |
# mulander@craig-laptop:~/art/bench$ python test.py | |
# 1.93834280968 | |
# 1.26033616066 | |
# mulander@craig-laptop:~/art/bench$ | |
import timeit | |
def flatten_iter(entry): | |
output = [] | |
for item in entry: | |
for el in item: | |
output.append(el) | |
return output | |
def flatten_lcomp(entry): | |
return [el for item in entry for el in item] | |
print timeit.timeit("flatten_iter([[1], [2,3,45], [1,3], [6], [8]])", setup="from __main__ import flatten_iter") | |
print timeit.timeit("flatten_lcomp([[1], [2,3,45], [1,3], [6], [8]])", setup="from __main__ import flatten_lcomp") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment