Skip to content

Commit 2c2b1c8

Browse files
committed
Some fixes for the memory_profiler module in benchmark
1 parent dfe6c92 commit 2c2b1c8

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

bench/ndarray/slice-expr.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
# Imports
1+
#######################################################################
2+
# Copyright (c) 2019-present, Blosc Development Team <[email protected]>
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under a BSD-style license (found in the
6+
# LICENSE file in the root directory of this source tree)
7+
#######################################################################
8+
9+
# Benchmark for computing a slice of a expression in a 4D array.
10+
211
import numpy as np
312
import blosc2
413
import time
5-
from memory_profiler import memory_usage
14+
from memory_profiler import memory_usage, profile
615
import matplotlib.pyplot as plt
716

817
file = "dset-ones.b2nd"
@@ -26,46 +35,52 @@
2635
print(f"Time to create expression: {time.time() - t:.6f} seconds")
2736

2837
# dim0
38+
@profile
2939
def slice_dim0():
3040
t = time.time()
3141
res = expr[1]
3242
t0 = time.time() - t
3343
print(f"Time to access dim0: {t0:.6f} seconds")
44+
print(f"dim0 slice size: {np.prod(res.shape) * res.dtype.itemsize / 2**30:.6f} GB")
3445

3546
# dim1
47+
@profile
3648
def slice_dim1():
3749
t = time.time()
3850
res = expr[:,1]
3951
t1 = time.time() - t
4052
print(f"Time to access dim1: {t1:.6f} seconds")
53+
print(f"dim1 slice size: {np.prod(res.shape) * res.dtype.itemsize / 2**30:.6f} GB")
4154

4255
# dim2
56+
@profile
4357
def slice_dim2():
4458
t = time.time()
4559
res = expr[:,:,1]
4660
t2 = time.time() - t
4761
print(f"Time to access dim2: {t2:.6f} seconds")
62+
print(f"dim2 slice size: {np.prod(res.shape) * res.dtype.itemsize / 2**30:.6f} GB")
4863

4964
# dim3
65+
@profile
5066
def slice_dim3():
5167
t = time.time()
5268
res = expr[:,:,:,1]
53-
#res = expr[1]
5469
t3 = time.time() - t
55-
5670
print(f"Time to access dim3: {t3:.6f} seconds")
71+
print(f"dim3 slice size: {np.prod(res.shape) * res.dtype.itemsize / 2**30:.6f} GB")
5772

58-
fig = plt.figure()
59-
interval = 0.001
60-
offset = 0
61-
for f in [slice_dim0, slice_dim1, slice_dim2, slice_dim3]:
62-
mem = memory_usage((f,), interval=interval)
63-
times = offset + interval * np.arange(len(mem))
64-
offset = times[-1]
65-
plt.plot(times, mem)
73+
if __name__ == '__main__':
74+
interval = 0.001
75+
offset = 0
76+
for f in [slice_dim0, slice_dim1, slice_dim2, slice_dim3]:
77+
mem = memory_usage((f,), interval=interval)
78+
times = offset + interval * np.arange(len(mem))
79+
offset = times[-1]
80+
plt.plot(times, mem)
6681

67-
plt.xlabel('Time (s)')
68-
plt.ylabel('Memory usage (MiB)')
69-
plt.title('Memory usage over time for slicing operations, slice-expr.py')
70-
plt.legend(['dim0', 'dim1', 'dim2', 'dim3'])
71-
plt.savefig('plots/slice-expr.png', format="png")
82+
plt.xlabel('Time (s)')
83+
plt.ylabel('Memory usage (MiB)')
84+
plt.title('Memory usage lazyexpr slice (fast path), Linux Blosc2 3.5.1')
85+
plt.legend(['expr[1]', 'expr[:,1]', 'expr[:,:,1]', 'expr[:,:,:,1]'])
86+
plt.savefig('Linux_Blosc3_5_1_fast.png', format="png")

0 commit comments

Comments
 (0)