Skip to content

Instantly share code, notes, and snippets.

@graph226
Created January 3, 2017 13:15
Show Gist options
  • Save graph226/522281f3ccc40034206b49ab441ebf5c to your computer and use it in GitHub Desktop.
Save graph226/522281f3ccc40034206b49ab441ebf5c to your computer and use it in GitHub Desktop.
Comparing log performance in Python
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