-1

I have multiple functions and I want to measure the performance of each and store elapsed time in a list. I am a bit confused about running these functions in the time measure function:

def time_measure(function):
    import time
    t = time.process_time()
    # run function here
    elapsed_time = time.process_time() - t
    output = []
    output.append(elapsed time)
    return output

or I think I can just run time_measure for each of the functions and get the time measurements separately. I have five functions to run.

How do I run the function within the time_measure function, and set the function as a parameter?

halo09876
  • 2,725
  • 12
  • 51
  • 71

1 Answers1

1

It's easy to measure the time of a function in iPython and you don't need to write any code.

Start iPython and enter your code:

import time 

def SomeFunction(): 
    time.sleep(0.337)
    return

Now you can time calls to that function:

%timeit SomeFunction()
339 ms ± 1.72 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

If you want to time multiple statements, use %%timeit:

%%timeit 
     SomeFunction() 
     SomeFunction() 
     SomeFunction() 

1.02 s ± 2.23 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432