def profile(self, fct, **kwargs): """ Profiles function *fct*, calls it *repeat* times. @param fct function to profile (no argument) @param kwargs stores additional information about the profiling """ if self.module in ('pyinstrument', 'cProfile'): if self.module == 'pyinstrument': profiler = Profiler(interval=self.interval) start = profiler.start stop = profiler.stop else: profiler = c_Profile() start = profiler.enable stop = profiler.disable start() for _ in range(self.repeat): fct() stop() elif self.module == "profile": profiler = py_Profile() def lf(): for _ in range(self.repeat): fct() profiler.runcall(lf) else: raise ValueError( # pragma: no cover "Unknown profiler '{}'.".format(self.module)) self.profiled.append(profiler) self.kwargs.append(kwargs)