Skip to content

Instantly share code, notes, and snippets.

@n-eq
Last active April 23, 2017 13:16

Revisions

  1. n-eq revised this gist Apr 23, 2017. 1 changed file with 2 additions and 6 deletions.
    8 changes: 2 additions & 6 deletions cache_blocking.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    import numpy as np
    import matplotlib.pyplot as plt
    import timeit
    @@ -13,12 +12,9 @@
    start_time=timeit.default_timer()
    for i in range(b):
    for j in range(b):
    ii=i
    jj=j
    while (ii < min(i + b, n)):
    while (jj < min(j + b, n)):
    for ii in range(i, min(i + b, n) + 1, b):
    for jj in range(j, min(j + b, n) + 1, b):
    tab[ii][jj] = np.random.rand()
    jj += b
    ii += b
    elapsed = timeit.default_timer() - start_time
    print("block: " + str(b) + ", elapsed: " + str(elapsed))
  2. n-eq created this gist Apr 23, 2017.
    30 changes: 30 additions & 0 deletions cache_blocking.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@

    import numpy as np
    import matplotlib.pyplot as plt
    import timeit

    plt.ion()

    n=10000
    block=[i+1 for i in range(1000)]
    time=[]
    tab=[[0 for i in range(n)] for j in range(n)]
    for b in block:
    start_time=timeit.default_timer()
    for i in range(b):
    for j in range(b):
    ii=i
    jj=j
    while (ii < min(i + b, n)):
    while (jj < min(j + b, n)):
    tab[ii][jj] = np.random.rand()
    jj += b
    ii += b
    elapsed = timeit.default_timer() - start_time
    print("block: " + str(b) + ", elapsed: " + str(elapsed))
    time.append(elapsed)
    plt.scatter(b, elapsed)
    plt.pause(0.05)

    while True:
    plt.pause(0.05)