def stats_run(npart, nproc, ndim, periodic=False, overwrite=False,
display=False, suppress_final_output=False):
r"""Get timing stats using :package:`cProfile`.
Args:
npart (int): Number of particles.
nproc (int): Number of processors.
ndim (int): Number of dimensions.
periodic (bool, optional): If True, the domain is assumed to be
periodic. Defaults to False.
overwrite (bool, optional): If True, the existing file for this
set of input parameters if overwritten. Defaults to False.
suppress_final_output (bool, optional): If True, the final output
from spawned MPI processes is suppressed. This is mainly for
timing purposes. Defaults to False.
display (bool, optional): If True, display the profile results.
Defaults to False.
"""
perstr = ""
outstr = ""
if periodic:
perstr = "_periodic"
if suppress_final_output:
outstr = "_noout"
fname_stat = 'stat_{}part_{}proc_{}dim{}{}.txt'.format(
npart, nproc, ndim, perstr, outstr)
if overwrite or not os.path.isfile(fname_stat):
cProfile.run(
"from cykdtree.tests import run_test; "+
"run_test({}, {}, nproc={}, ".format(npart, ndim, nproc) +
"periodic={}, ".format(periodic) +
"suppress_final_output={})".format(suppress_final_output),
fname_stat)
if display:
p = pstats.Stats(fname_stat)
p.sort_stats('time').print_stats(10)
return p
return fname_stat
评论列表
文章目录