def run_all_tests(): # auto discover unittests from test_*.py files into the timemory test suite timTestSuite = unittest.defaultTestLoader.discover( start_dir=os.path.dirname(os.path.abspath(__file__)), pattern="test*.py", ) # print the loaded tests print("============= Loaded Tests =============\n\n {}\n".format( timTestSuite)) # create a results object to store test results result = unittest.TestResult() # enable stdout buffer result.buffer = True # run all tests in timTestSuite, use result object to store results print("\n============= Tests Stdout =============\n") # run the tests timTestSuite.run(result) # finalize tracing tim.trace.finalize() # finalize timemory tim.finalize() # print the results print("\n============= Results =============\n") print("{}\n".format(result)) return result
#!@PYTHON_EXECUTABLE@ import sys import timemory from timemory.profiler import profile def fib(n): return n if n < 2 else (fib(n - 1) + fib(n - 2)) @profile(["wall_clock", "peak_rss"]) def run_profile(nfib): return fib(nfib) if __name__ == "__main__": nfib = int(sys.argv[1]) if len(sys.argv) > 1 else 23 ans = run_profile(nfib) print("Answer = {}".format(ans)) timemory.finalize()
def finalize(): timemory.finalize()