Skip to content

Commit 6572456

Browse files
committed
Fix average increase calculation by tracking peaks
1 parent 05c347f commit 6572456

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

unit/memleak.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ def run_memleak_test(bench, iterations, report):
1818

1919
malloc_arr = np.empty((endi,), dtype=np.int64)
2020
rss_arr = np.empty((endi,), dtype=np.int64)
21+
rss_peaks = np.empty((endi,), dtype=np.int64)
2122
nobjs_arr = np.empty((endi,), dtype=np.int64)
2223
garbage_arr = np.empty((endi,), dtype=np.int64)
24+
rss_peak = 0
2325

2426
for i in range(endi):
2527
bench()
@@ -34,11 +36,14 @@ def run_memleak_test(bench, iterations, report):
3436

3537
malloc_arr[i] = malloc
3638
rss_arr[i] = rss
39+
if rss > rss_peak:
40+
rss_peak = rss
41+
rss_peaks[i] = rss_peak
3742
nobjs_arr[i] = nobjs
3843
garbage_arr[i] = garbage
3944

4045
print('Average memory consumed per loop: %1.4f bytes\n' %
41-
(np.sum(rss_arr[starti+1:] - rss_arr[starti:-1]) / float(endi - starti)))
46+
(np.sum(rss_peaks[starti+1:] - rss_peaks[starti:-1]) / float(endi - starti)))
4247

4348
from matplotlib import pyplot as plt
4449
fig, (ax1, ax2) = plt.subplots(2)

0 commit comments

Comments
 (0)