Created
April 18, 2018 11:07
-
-
Save walkingmask/4f473335e9e319f4a9421ac750423103 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
import numpy as np | |
import timeit | |
def f(x, y): | |
return (x+1)*y | |
def ff(X, y): | |
res = [] | |
for x in X: | |
res.append(f(x,y)) | |
return res | |
def mf(X, y): | |
return list(map(lambda x: f(x,y), X)) | |
def cf(X, y): | |
return [f(x,y) for x in X] | |
vf = np.vectorize(f) | |
X = [i for i in range(10000)] | |
y = 12345 | |
print(timeit.timeit('ff(X,y)', globals=globals(), number=1000)) | |
print(timeit.timeit('mf(X,y)', globals=globals(), number=1000)) | |
print(timeit.timeit('cf(X,y)', globals=globals(), number=1000)) | |
print(timeit.timeit('vf(X,y)', globals=globals(), number=1000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
results
The process was too simple?