Last active
October 12, 2018 17:15
-
-
Save ysinjab/a4a05e6e3eaca8fbdbc39f0f3d3fdeef 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
def append_to_list(size=1000000): | |
result = [] | |
for i in range(size): | |
result.append(1) | |
def fill_pre_allocated_list(size=1000000): | |
result = size * [None] | |
for i in range(size): | |
result[i]= 1 | |
%timeit append_to_list() | |
# 10 loops, best of 3: 150 ms per loop | |
%timeit fill_pre_allocated_list() | |
# 10 loops, best of 3: 111 ms per loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment