Skip to content

Commit 8082495

Browse files
committed
Display more info in bench, specially speedup wrt NumPy
1 parent 7eabaf0 commit 8082495

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

bench/ndarray/compute_where.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import blosc2
1515

16-
shape = (4_000, 5_000)
16+
shape = (40_000, 5_000)
1717
chunks = (10, 5_000)
1818
blocks = (1, 1000)
1919
# Comment out the next line to force chunks and blocks above
@@ -33,13 +33,13 @@
3333
t0 = time()
3434
npc = npa**2 + npb**2 > 2 * npa * npb + 1
3535
npd = np.where(npc, 0, 1)
36-
t = time() - t0
36+
tref = t = time() - t0
3737
print(f"Time to compute where expression (NumPy): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s")
3838

3939
t0 = time()
4040
npc = ne.evaluate('where(a**2 + b**2 > 2 * a * b + 1, 0, 1)', local_dict={'a': npa, 'b': npb})
4141
t = time() - t0
42-
print(f"Time to compute where expression (NumExpr): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s")
42+
print(f"Time to compute where expression (NumExpr): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s; {tref / t:.1f}x wrt NumPy")
4343

4444
s = blosc2.asarray(nps, chunks=chunks, blocks=blocks, cparams=cparams)
4545
print(f"*** Working with NDArray with shape: {s.shape}, chunks: {s.chunks}, blocks: {s.blocks},"
@@ -53,43 +53,43 @@
5353
c = a**2 + b**2 > 2 * a * b + 1
5454
d = c.where(0, 1).compute(cparams=cparams)
5555
t = time() - t0
56-
print(f"Time to compute where expression (compute): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s")
56+
print(f"Time to compute where expression (compute): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s; {tref / t:.1f}x wrt NumPy")
5757

5858
# Compute the whole slice: output is a NumPy array
5959
t0 = time()
6060
c = a**2 + b**2 > 2 * a * b + 1
6161
npd = c.where(0, 1)[:]
6262
t = time() - t0
63-
print(f"Time to compute where expression (getitem): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s")
63+
print(f"Time to compute where expression (getitem): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s; {tref / t:.1f}x wrt NumPy")
6464

6565
print("*** Extracting rows")
6666
# Compute and get row values: NumPy
6767
t0 = time()
6868
npc = npa**2 + npb**2 > 2 * npa * npb + 1
6969
npd = nps[npc]
70-
t = time() - t0
70+
tref = t = time() - t0
7171
print(f"Time to get row values (NumPy): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s")
7272

7373
# Compute and get row values: output is a NDArray
7474
t0 = time()
7575
npd = s[a**2 + b**2 > 2 * a * b + 1].compute(cparams=cparams)
7676
t = time() - t0
77-
print(f"Time to get row values (compute): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s")
77+
print(f"Time to get row values (compute): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s; {tref / t:.1f}x wrt NumPy")
7878

7979
# Compute and get row values: output is a NDArray
8080
t0 = time()
8181
npd = s['a**2 + b**2 > 2 * a * b + 1'].compute(cparams=cparams)
8282
t = time() - t0
83-
print(f"Time to get row values (compute, string): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s")
83+
print(f"Time to get row values (compute, string): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s; {tref / t:.1f}x wrt NumPy")
8484

8585
# Compute and get row values: output is a NumPy array
8686
t0 = time()
8787
npd = s[a**2 + b**2 > 2 * a * b + 1][:]
8888
t = time() - t0
89-
print(f"Time to get row values (getitem): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s")
89+
print(f"Time to get row values (getitem): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s; {tref / t:.1f}x wrt NumPy")
9090

9191
# Compute and get row values: output is a NumPy array
9292
t0 = time()
9393
npd = s['a**2 + b**2 > 2 * a * b + 1'][:]
9494
t = time() - t0
95-
print(f"Time to get row values (getitem, string): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s")
95+
print(f"Time to get row values (getitem, string): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s; {tref / t:.1f}x wrt NumPy")

bench/ndarray/reduce_expr.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import blosc2
1919

20-
shape = (50, 100, 10_000)
21-
chunks = [5, 100, 10_000]
20+
shape = (100, 100, 10_000)
21+
chunks = [10, 100, 10_000]
2222
blocks = [4, 10, 1_000]
2323
# Comment out the next line to force chunks and blocks above
2424
chunks, blocks = None, None
@@ -41,6 +41,7 @@
4141
x = blosc2.asarray(npx, chunks=chunks, blocks=blocks)
4242
y = blosc2.asarray(npy, chunks=chunks, blocks=blocks)
4343
z = blosc2.asarray(npz, chunks=chunks, blocks=blocks)
44+
print(f"*** cratios: x={x.schunk.cratio:.2f}x, y={y.schunk.cratio:.2f}x, z={z.schunk.cratio:.2f}x")
4445

4546
expr = "(x**2 + y**2 * z** 2) < 1"
4647

@@ -52,24 +53,28 @@
5253
npexpr = expr.replace("sin", "np.sin").replace("cos", "np.cos")
5354
t0 = time()
5455
npres = eval(npexpr, vardict).sum(axis=axis)
55-
print("NumPy took %.3f s" % (time() - t0))
56+
tref = time() - t0
57+
print("NumPy took %.3f s" % tref)
5658
# ne.set_num_threads(1)
5759
# nb.set_num_threads(1) # this does not work that well; better use the NUMBA_NUM_THREADS env var
5860
t0 = time()
5961
out = ne.evaluate(expr, vardict).sum(axis=axis)
60-
print("NumExpr took %.3f s" % (time() - t0))
62+
t1 = time() - t0
63+
print(f"NumExpr took {t1:.3f} s; {tref / t1:.1f}x wrt NumPy")
6164

6265
# Reduce with Blosc2
6366
c = eval(expr)
6467
t0 = time()
6568
d = c.compute()
6669
d = d.sum(axis=axis)
67-
print("LazyExpr+compute took %.3f s" % (time() - t0))
70+
t1 = time() - t0
71+
print(f"LazyExpr+compute took {t1:.3f} s; {tref / t1:.1f}x wrt NumPy")
6872
# Check
6973
np.testing.assert_allclose(d[()], npres, rtol=rtol, atol=atol)
7074
t0 = time()
7175
d = c[:]
7276
d = d.sum(axis=axis)
73-
print("LazyExpr+getitem took %.3f s" % (time() - t0))
77+
t1 = time() - t0
78+
print(f"LazyExpr+getitem took {t1:.3f} s; {tref / t1:.1f}x wrt NumPy")
7479
# Check
7580
np.testing.assert_allclose(d[()], npres, rtol=rtol, atol=atol)

0 commit comments

Comments
 (0)