Skip to content

Instantly share code, notes, and snippets.

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