Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python timeit function return value

import time

# Function with both args and kwargs ====
def time_fn( fn, *args, **kwargs ):
    start = time.perf_counter()
    results = fn( *args, **kwargs )
    end = time.perf_counter()
    print(fn.__name__ + ": " + str(end-start) + "s")
    return results

res = time_fn(function_name, input, output)

# Function with only arguments ====
def time_fn(fn, *args):
    start = time.perf_counter()
    results = fn(*args)
    end = time.perf_counter()
    print(fn.__name__ + ": " + str(end - start) + "s")
    return results

res = time_fn(function_name, input)
Comment

PREVIOUS NEXT
Code Example
Python :: turn off colorbar seaborn heatmap 
Python :: Python NumPy append Function Syntax 
Python :: python draw tree 
Python :: text color python tkinter 
Python :: get schema of json pyspark 
Python :: python import matplotlib 
Python :: python print variable and string 
Python :: normalize function 
Python :: pandas df.index.values 
Python :: sum values in django models and insert value in model field 
Python :: change tuple python 
Python :: discordpy make all inputs lowercase 
Python :: python calculations with variable x (letter) 
Python :: How do I schedule an email to send at a certain time using cron and smtp, in python 
Python :: dockerize django app 
Python :: pdf to excel conversion using python 
Python :: multiple assessment in python 
Python :: how to make a random question generator in python 
Python :: os.path.dirname(__file__) 
Python :: reading csv in spark 
Python :: import csv as dic 
Python :: python get object parameters 
Python :: py list 3d 
Python :: why python stops after plt.show() 
Python :: python split space or tab 
Python :: flask production server 
Python :: print index and value on each iteration of the for loop in Python 
Python :: Python __floordiv__ 
Python :: iterate rows and columns dataframe 
Python :: pandas data frame from part of excel better example 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =