python - I want to eavalute the time needed to perform prediction using a trained model -


this question has answer here:

i know timeit can used measure elapsed time, don't how implement in code. example, evaluate model performance follows:

scores = model.evaluate(x_test, y_test, verbose=0) 

how add timeit or other functions measure time needed?

here basic setup:

import time start_time = time.time() # code print("time - {}".format(time.time()-start_time)) 

you can make use of python's function wrappers, , make wrapper time functions. eg.

import time  def getime(func):     def func_wrapper(*args, **kwargs):         start_time = time.time()         func(*args, **kwargs)         print("function {} completed in - {} seconds".format(             func.__name__,             time.time()-start_time))     return func_wrapper  # ------------ test example of wrapper --------- # @getime def foo():     in range(1000):         j in range(2000):             pass  foo() 

output:

function foo completed in - 0.13300752639770508 seconds 

Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -