A function that measures the processing time of a method in python

It is a function that measures methods and functions as a whole. It's python2.7.


Put the number of repetitions at the end of the argument

import time
def timer_handler(func, *args):
    #As pointed out by hiracamus, time.time()Fixed from
    start = time.clock() 
    count = args[-1]
    args2 = args[:-1]
    for i in range(count):
        rtn = func(*args2)
    elapsed_time = time.clock() - start
    print("time = " + str(elapsed_time))
    return rtn

How to use

Processing time when executed 10,000 times repeatedly

def test(a,b,c):
    return pow(a,pow(b,c))

loop = 10000
v = timer_handler(test, 2,3,3, loop)
print v


time = 0.024491071701 134217728

Recommended Posts

A function that measures the processing time of a method in python
Get the caller of a function in Python
Python: I want to measure the processing time of a function neatly
The story of blackjack A processing (python)
[Python3] Define a decorator to measure the execution time of a function
Draw a graph of a quadratic function in Python
View the result of geometry processing in Python
Make a copy of the list in Python
A clever way to time processing in Python
Output in the form of a python array
Receive a list of the results of parallel processing in Python with starmap
The eval () function that calculates a string as an expression in python
Get a datetime instance at any time of the day in Python
[Python] Note: A self-made function that finds the area of the normal distribution
[Python] A program that counts the number of valleys
Create a function in Python
[Python] Measures and displays the time required for processing
# Function that returns the character code of a string
A reminder about the implementation of recommendations in Python
[Python] A program that compares the positions of kangaroos.
What does the last () in a function mean in Python?
A memo that implements the job of loading a GCS file into BigQuery in Python
How to unit test a function containing the current time using freezegun in python
Check the processing time and the number of calls for each process in python (cProfile)
Find out the apparent width of a string in python
A simple Python implementation of the k-nearest neighbor method (k-NN)
A function that divides iterable into N pieces in Python
How to use the __call__ method in a Python class
Processing of python3 that seems to be usable in paiza
Have the equation graph of the linear function drawn in Python
Get the number of specific elements in a python list
[Note] Import of a file in the parent directory in Python
A memo of writing a basic function in Python using recursion
A set of script files that do wordcloud in Python3
Find the eigenvalues of a real symmetric matrix in Python
A Python script that compares the contents of two directories
Measure function execution time in Python
[Python] Make the function a lambda function
[C / C ++] Pass the value calculated in C / C ++ to a python function to execute the process, and use that value in C / C ++.
[Python] Programming to find the number of a in a character string that repeats a specified number of times.
Play a sound in Python assuming that the keyboard is a piano keyboard
How to determine the existence of a selenium element in Python
I compared the calculation time of the moving average written in Python
A story that struggled to handle the Python package of PocketSphinx
Try transcribing the probability mass function of the binomial distribution in Python
How to check the memory size of a variable in Python
[Python] Execution time when a function is entered in a dictionary value
Read the standard output of a subprocess line by line in Python
How to check the memory size of a dictionary in Python
Create a function to get the contents of the database in Go
[python] A note that started to understand the behavior of matplotlib.pyplot
The story of making a module that skips mail with python
[Python] A simple function to find the center coordinates of a circle
[Python] A program that rotates the contents of the list to the left
Get the number of readers of a treatise on Mendeley in Python
Check the behavior of destructor in Python
Precautions when pickling a function in python
Write the test in a python docstring
Display a list of alphabets in Python 3
OR the List in Python (zip function)
Put the process to sleep for a certain period of time (seconds) or more in Python