|
| 1 | +import blosc2 |
| 2 | +import numpy as np |
| 3 | +import time |
| 4 | + |
| 5 | +N = 10000 |
| 6 | +ndim = 2 |
| 7 | +ashape = (N,) * ndim |
| 8 | +bshape = ashape |
| 9 | +dtype = np.float64 |
| 10 | + |
| 11 | +achunks = (1000, 1000) |
| 12 | +bchunks = (achunks[1], achunks[0]) |
| 13 | +ablocks = (200, 200) |
| 14 | +bblocks = (ablocks[1], ablocks[0]) |
| 15 | +outblocks = (ablocks[0], bblocks[1]) |
| 16 | +outchunks = (achunks[0], bchunks[1]) |
| 17 | +# a = blosc2.linspace(0, 1, dtype=dtype, shape=ashape, chunks=achunks, blocks=ablocks) |
| 18 | +# b = blosc2.linspace(0, 1, dtype=dtype, shape=bshape, chunks=bchunks, blocks=bblocks) |
| 19 | +a = blosc2.ones(dtype=dtype, shape=ashape, chunks=achunks, blocks=ablocks) |
| 20 | +b = blosc2.full(fill_value=2, dtype=dtype, shape=bshape, chunks=bchunks, blocks=bblocks) |
| 21 | + |
| 22 | +a_np = a[:] |
| 23 | +b_np = b[:] |
| 24 | +tic = time.time() |
| 25 | +np_res = np.matmul(a_np, b_np) |
| 26 | +print(f'numpy finished in {time.time()-tic} s') |
| 27 | + |
| 28 | +tic = time.time() |
| 29 | +b2_res = blosc2.matmul(a, b, blocks=outblocks, chunks=outchunks) |
| 30 | +print(f'blosc2 multithreaded finished in {time.time()-tic} s') |
| 31 | + |
| 32 | +tic = time.time() |
| 33 | +b2_res = blosc2.matmul(a, b) |
| 34 | +print(f'blosc2 normal finished in {time.time()-tic} s') |
| 35 | + |
| 36 | +achunks = None #(1000, 1000) |
| 37 | +bchunks = None #(achunks[1], achunks[0]) |
| 38 | +ablocks = None #(200, 200) |
| 39 | +bblocks = None #(ablocks[1], ablocks[0]) |
| 40 | +outblocks = None #(ablocks[0], bblocks[1]) |
| 41 | +outchunks = None #(achunks[0], bchunks[1]) |
| 42 | +# a = blosc2.linspace(0, 1, dtype=dtype, shape=ashape, chunks=achunks, blocks=ablocks) |
| 43 | +# b = blosc2.linspace(0, 1, dtype=dtype, shape=bshape, chunks=bchunks, blocks=bblocks) |
| 44 | +a = blosc2.ones(dtype=dtype, shape=ashape, chunks=achunks, blocks=ablocks) |
| 45 | +b = blosc2.full(fill_value=2, dtype=dtype, shape=bshape, chunks=bchunks, blocks=bblocks) |
| 46 | +tic = time.time() |
| 47 | +b2_res = blosc2.matmul(a, b, blocks=outblocks, chunks=outchunks) |
| 48 | +print(f'blosc2 normal with default chunks etc. finished in {time.time()-tic} s') |
0 commit comments