Run function `run` and print timing information. Parameters ---------- run : callable Any callable object which takes no argument. nruns : int Number of times to execute `run`.
(run, nruns)
| 968 | |
| 969 | @staticmethod |
| 970 | def _run_with_timing(run, nruns): |
| 971 | """ |
| 972 | Run function `run` and print timing information. |
| 973 | |
| 974 | Parameters |
| 975 | ---------- |
| 976 | run : callable |
| 977 | Any callable object which takes no argument. |
| 978 | nruns : int |
| 979 | Number of times to execute `run`. |
| 980 | |
| 981 | """ |
| 982 | twall0 = time.perf_counter() |
| 983 | if nruns == 1: |
| 984 | t0 = clock2() |
| 985 | run() |
| 986 | t1 = clock2() |
| 987 | t_usr = t1[0] - t0[0] |
| 988 | t_sys = t1[1] - t0[1] |
| 989 | print("\nIPython CPU timings (estimated):") |
| 990 | print(" User : %10.2f s." % t_usr) |
| 991 | print(" System : %10.2f s." % t_sys) |
| 992 | else: |
| 993 | runs = range(nruns) |
| 994 | t0 = clock2() |
| 995 | for nr in runs: |
| 996 | run() |
| 997 | t1 = clock2() |
| 998 | t_usr = t1[0] - t0[0] |
| 999 | t_sys = t1[1] - t0[1] |
| 1000 | print("\nIPython CPU timings (estimated):") |
| 1001 | print("Total runs performed:", nruns) |
| 1002 | print(" Times : %10s %10s" % ('Total', 'Per run')) |
| 1003 | print(" User : %10.2f s, %10.2f s." % (t_usr, t_usr / nruns)) |
| 1004 | print(" System : %10.2f s, %10.2f s." % (t_sys, t_sys / nruns)) |
| 1005 | twall1 = time.perf_counter() |
| 1006 | print("Wall time: %10.2f s." % (twall1 - twall0)) |
| 1007 | |
| 1008 | @skip_doctest |
| 1009 | @no_var_expand |