[Numpy-discussion] where are the benefits of ldexp and/or "array times 2"?
dmitrey
dmitrey.kroshko@scipy....
Thu May 21 10:26:45 CDT 2009
Hi all,
I expected to have some speedup via using ldexp or multiplying an
array by a power of 2 (doesn't it have to perform a simple shift of
mantissa?), but I don't see the one.
Have I done something wrong? See the code below.
from scipy import rand
from numpy import dot, ones, zeros, array, ldexp
from time import time
N = 1500
A = rand(N, N)
b = rand(N)
b2 = 2*ones(A.shape, 'int32')
I = 100
t = time()
for i in xrange(I):
dot(A, b) # N^2 multiplications + some sum operations
#A * 2.1 # N^2 multiplications, so it should consume no greater
than 1st line time
#ldexp(A, b2) # it should consume no greater than prev line time,
isn't it?
print 'time elapsed:', time() - t
# 1st case: 0.62811088562
# 2nd case: 2.00850605965
# 3rd case: 6.79027700424
# Let me also note -
# 1) using b = 2 * ones(N) or b = zeros(N) doesn't yield any speedup
vs b = rand()
# 2) using A * 2.0 (or mere 2) instead of 2.1 doesn't yield any
speedup, despite it is exact integer power of 2.
More information about the Numpy-discussion
mailing list