timings_out(reps,func,*args,**kw) -> (t_total,t_per_call,output) Execute a function reps times, return a tuple with the elapsed total CPU time in seconds, the time per call and the function's output. Under Unix, the return value is the sum of user+system time consumed by the proces
(reps,func,*args,**kw)
| 68 | |
| 69 | |
| 70 | def timings_out(reps,func,*args,**kw): |
| 71 | """timings_out(reps,func,*args,**kw) -> (t_total,t_per_call,output) |
| 72 | |
| 73 | Execute a function reps times, return a tuple with the elapsed total |
| 74 | CPU time in seconds, the time per call and the function's output. |
| 75 | |
| 76 | Under Unix, the return value is the sum of user+system time consumed by |
| 77 | the process, computed via the resource module. This prevents problems |
| 78 | related to the wraparound effect which the time.clock() function has. |
| 79 | |
| 80 | Under Windows the return value is in wall clock seconds. See the |
| 81 | documentation for the time module for more details.""" |
| 82 | |
| 83 | reps = int(reps) |
| 84 | assert reps >=1, 'reps must be >= 1' |
| 85 | if reps==1: |
| 86 | start = clock() |
| 87 | out = func(*args,**kw) |
| 88 | tot_time = clock()-start |
| 89 | else: |
| 90 | rng = range(reps-1) # the last time is executed separately to store output |
| 91 | start = clock() |
| 92 | for dummy in rng: func(*args,**kw) |
| 93 | out = func(*args,**kw) # one last time |
| 94 | tot_time = clock()-start |
| 95 | av_time = tot_time / reps |
| 96 | return tot_time,av_time,out |
| 97 | |
| 98 | |
| 99 | def timings(reps,func,*args,**kw): |