Skip to content

Commit be556dc

Browse files
author
y-p
committed
BLD: test_perf, do a collect once per --repeats, after each b.run()
1 parent a7b5deb commit be556dc

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

vb_suite/test_perf.py

+35-32
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,6 @@ def prprint(s):
133133

134134
def pre_hook():
135135
import gc
136-
gc.collect()
137-
138-
try:
139-
from ctypes import cdll, CDLL
140-
cdll.LoadLibrary("libc.so.6")
141-
libc = CDLL("libc.so.6")
142-
libc.malloc_trim(0)
143-
except:
144-
pass
145-
146136
gc.disable()
147137

148138
def post_hook():
@@ -231,36 +221,49 @@ def profile_comparative(benchmarks):
231221

232222

233223
def profile_head_single(benchmark):
224+
import gc
234225
results = []
235226

227+
# just in case
228+
gc.collect()
229+
230+
try:
231+
from ctypes import cdll, CDLL
232+
cdll.LoadLibrary("libc.so.6")
233+
libc = CDLL("libc.so.6")
234+
libc.malloc_trim(0)
235+
except:
236+
pass
237+
236238

237239
N = args.hrepeats + args.burnin
238240

239241
results = []
240-
for i in range(N):
241-
pre_hook() # gc collect then disable
242-
243-
d=dict()
244-
sys.stdout.write('.')
245-
sys.stdout.flush()
246-
try:
247-
d = benchmark.run()
248-
249-
except KeyboardInterrupt:
250-
raise
251-
except Exception as e: # if a single vbench bursts into flames, don't die.
252-
err=""
253-
try:
254-
err = d.get("traceback")
255-
if err is None:
256-
err = str(e)
257-
except:
258-
pass
259-
print("%s died with:\n%s\nSkipping...\n" % (benchmark.name, err))
242+
try:
243+
for i in range(N):
244+
gc.disable()
245+
d=dict()
260246

261-
results.append(d.get('timing',np.nan))
247+
try:
248+
d = benchmark.run()
249+
250+
except KeyboardInterrupt:
251+
raise
252+
except Exception as e: # if a single vbench bursts into flames, don't die.
253+
err=""
254+
try:
255+
err = d.get("traceback")
256+
if err is None:
257+
err = str(e)
258+
except:
259+
pass
260+
print("%s died with:\n%s\nSkipping...\n" % (benchmark.name, err))
261+
262+
results.append(d.get('timing',np.nan))
263+
gc.enable()
262264

263-
post_hook() # gc enable
265+
finally:
266+
gc.enable()
264267

265268
if results:
266269
# throw away the burn_in

0 commit comments

Comments
 (0)