python3 Measure the processing speed.

Introduction

This article is a main learning note for python beginners. Describes how to measure the time taken for processing with python.

Sample code

speed.py


# coding utf-8
import time

#Start measurement
start = time.time()
#Write the process here(Measure the time taken for this process(Stop here for 2 seconds))
time.sleep(2)
#End of measurement
end = time.time()
#Output measurement results
print(str(end-start) + ' seconds')

The processing speed can be calculated by [time when processing was completed-time when processing was started].

It is more accurate to use time.perf_counter than time.time.

When using perf_counter

speed.py


# coding utf-8
import time

start = time.perf_counter()
time.sleep(2)
end = time.perf_counter()
print(str(end-start) + ' seconds')

To be honest, I think you can use either one.

Recommended Posts

python3 Measure the processing speed.
Measure WiFi speed with Python
Leave the troublesome processing to Python
python image processing
Python file processing
The story of blackjack A processing (python)
Python: I want to measure the processing time of a function neatly
Operate the Speech Signal Processing Toolkit via python
About the processing speed of SVM (SVC) of scikit-learn
View the result of geometry processing in Python
Compare the speed of Python append and map
Image processing? The story of starting Python for
How to measure line speed from the terminal
I checked the processing speed of numpy one-dimensionalization
Python distributed processing Spartan
Find the maximum Python
File processing in Python
Python: Natural language processing
Python ~ Grammar speed learning ~
Communication processing by Python
Multithreaded processing in python
Python list comprehension speed
First Python image processing
the zen of Python
Text processing in Python
Queue processing in Python
Image processing with Python
[Python] Split the date
Python string processing illustration
Various processing of Python
How to measure processing time in Python or Java
[Python] Measures and displays the time required for processing
Examine the close processing of Python dataset (SQLAlchemy wrapper)
An easy way to measure the processing speed of a disk recognized by Linux
I tried to compare the processing speed with dplyr of R and pandas of Python
Image processing with Python (Part 2)
100 Language Processing with Python Knock 2015
How to increase the processing speed of vertex position acquisition
UTF8 text processing in python
Towards the retirement of Python2
"Apple processing" with OpenCV3 + Python3
Python, Java, C ++ speed comparison
Wrap C/C ++ with SWIG to speed up Python processing. [Overview]
Download the file in Python
Measure the execution result of the program in C ++, Java, Python.
Find the difference in Python
Measure BMI index in Python.
Compare the Python array-like guys
About the Python module venv
Acoustic signal processing with Python (2)
[Maya Python] Crush the contents of the script 1 ~ Camera Speed Editor
Acoustic signal processing with Python
About the ease of Python
About the enumerate function (python)
Asynchronous processing (threading) in python
100 Language Processing Knock Chapter 1 (Python)
[Python] Adjusting the color bar
100 Language Processing Knock Chapter 2 (Python)
Speed up the netstat command
Image processing with Python (Part 1)
[Python] Get the previous month