Last active
January 25, 2019 22:28
-
-
Save mocquin/8f61f628118ae60341baa11a8246d970 to your computer and use it in GitHub Desktop.
Element-wise data structure computation time
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
# Please note the results for larger list can be different | |
import numpy as np | |
# making a list, a dict, and an array | |
list_a = list(np.asarray(np.linspace(0,9,10)).astype(int)) # working with int | |
array_a = np.array(list_a) | |
dict_a = {x: x for x in list_a} | |
from operator import add as opadd | |
%timeit -r5 list_c = list(map(opadd, list_a, list_a)) | |
%timeit -r5 list_cc = [x+y for x,y in zip(list_a,list_a)] | |
%timeit -r5 array_c = array_a + array_a | |
%timeit -r5 dict_c = {dict_a[key] + dict_a[key] for key in dict_a.keys()} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment