# Numpy Bench browsing

• posted
0

``````import numpy as np
import time
import math

bt = time.time()
n = 1000
for i in range(1):
a = np.random.uniform(low=0., high=1., size=(n, n)).astype(np.float32)
b = np.random.uniform(low=0., high=1., size=(n, n)).astype(np.float32)
a = a.dot(b)
print ('(%d * %d),Total Time:%.3f'%(n,n,time.time()-bt))

start = time.clock()
x = [i * 0.001 for i in xrange(10000000)]
for i, t in enumerate(x):
x[i] = math.sin(t)
print ("math.sin:%.3f"%(time.clock() - start))

start = time.clock()
y = [i * 0.001 for i in xrange(10000000)]
y = np.array(y)
print ("numpy.sin1:%.3f"%(time.clock() - start))
start = time.clock()
np.sin(y,y)
print ("numpy.sin2:%.3f"%(time.clock() - start))

'''
(1000 * 1000),Total Time:8.840
math.sin: 3.04883
numpy.sin: 2.668903 (2.517,0.177)

=====Android Termux=====
(1000,1000) 0.627
math.sin: 33.899
numpy.sin: 14.953

=====MacBook Air 13 @2010====
(1000,1000) 0.234
math.sin: 8.95
numpy.sin: 4.71 (3.88,0.48)

====Microsoft Surface 3 @2015====
(1000,1000) 0.203
math.sin: 12.739
numpy.sin: (5.419,0.380)

``````

Why iOS numpy (1000,1000) very slow ???

• posted
0

is this the same exact code run on all devices? clearly not, since the output is different

Note the time here is the time to run random.uniform(1000,1000) twice, plus the dot product. The dot product is the time consuming bit.

• posted
0

all devices run same code.

• posted
0

it is not the same code, since the output is different form. maybe you use * instead of .dot() for the other platfoms?

Alternatively, perhaps the matrix multiplication is not well optimized on ios (i.e using all of the BLAS or Accelerate, etc)

• posted
0

I got the below from my iPad Pro 12.9' latest model and the latest beta. I ran it under 2.7 as I guess thats the target because of the use of xrange.

(1000 * 1000),Total Time:5.750
math.sin:2.757
numpy.sin1:2.156
numpy.sin2:0.131

• posted
0

iPhone X (Pythonista V3.2 , Python 2.7)

(1000 * 1000),Total Time:6.435
math.sin:2.250
numpy.sin1:1.697
numpy.sin2:0.111

• posted
1

as an aside -- you shouls never create arrays like this... use np.linspace! np.linspace(0,10,1000000) is about 10x faster than list comprehension!

Internal error.

Oops! Looks like something went wrong!