Created
January 3, 2017 13:15
-
-
Save graph226/522281f3ccc40034206b49ab441ebf5c to your computer and use it in GitHub Desktop.
Comparing log performance in Python
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 | |
start = time.time() | |
for i in num_list: | |
tmp = np.log2(i) | |
elapsed_time = time.time() - start | |
print(("elapsed_time:{0}".format(elapsed_time)) + "[sec]") | |
start = time.time() | |
for i in num_list: | |
tmp = math.log(i, 2) | |
elapsed_time = time.time() - start | |
print(("elapsed_time:{0}".format(elapsed_time)) + "[sec]") | |
# result | |
# elapsed_time:0.07547879219055176[sec] | |
# elapsed_time:0.02680182456970215[sec] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment