In [1]:
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
In [14]:
def changevals(A):
    for i in range(A.shape[0]):
        for j in range(A.shape[1]):
            A[i,j] = 55.0
In [15]:
n = 100
A = np.zeros((n,n))
%timeit changevals(A)
1000 loops, best of 3: 1.62 ms per loop
In [17]:
nlist = [5,10,50,100,200,300,400,500,1000]
tlist = []

for n in nlist:
    print("n=%d" % n)
    A = np.zeros((n,n))
    t = %timeit -n 1 -r 3 -o changevals(A)
    tlist.append(np.mean(t.all_runs))
n=5
1 loops, best of 3: 8.03 µs per loop
n=10
1 loops, best of 3: 22.3 µs per loop
n=50
1 loops, best of 3: 400 µs per loop
n=100
1 loops, best of 3: 1.69 ms per loop
n=200
1 loops, best of 3: 6.07 ms per loop
n=300
1 loops, best of 3: 14.6 ms per loop
n=400
1 loops, best of 3: 24.8 ms per loop
n=500
1 loops, best of 3: 42.6 ms per loop
n=1000
1 loops, best of 3: 170 ms per loop
In [18]:
plt.loglog(nlist, tlist, 'o')
Out[18]:
[<matplotlib.lines.Line2D at 0x115138908>]
In [ ]: