Created
January 3, 2017 13:43
-
-
Save graph226/d00f7dddf0f59923c405d583d5d16312 to your computer and use it in GitHub Desktop.
Comparing log performance in Python with vectrizing
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 math | |
import numpy as np | |
import time | |
num_list = list(np.random.rand(100000)*100000) | |
tmp = 0 | |
log_list = [] | |
start = time.time() | |
log_list = list(np.log2(num_list)) | |
elapsed_time = time.time() - start | |
print(("elapsed_time:{0}".format(elapsed_time)) + "[sec]") | |
log_list = [] | |
start = time.time() | |
log_list = [ math.log(i, 2) for i in num_list ] | |
elapsed_time = time.time() - start | |
print(("elapsed_time:{0}".format(elapsed_time)) + "[sec]") | |
# result | |
# elapsed_time:0.01147603988647461[sec] | |
# elapsed_time:0.019212961196899414[sec] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment