Output the time from the time the program was started in python

It just prints the time from the time you start the program in python.

test.py


#-*- using:utf-8 -*-
import time

if __name__ == '__main__':
    start_time = time.time()

    while True:
        time.sleep(1);
        elapsed_time = time.time() - start_time
        print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")

Execution result

$ python3 test.py
elapsed_time:1.0001800060272217[sec]
elapsed_time:2.0004279613494873[sec]
elapsed_time:3.0007290840148926[sec]
elapsed_time:4.001792907714844[sec]
elapsed_time:5.0019917488098145[sec]

reference

time --- Accessing and converting time data

Recommended Posts

Output the time from the time the program was started in python
MongoDB for the first time in Python
Read a file in Python with a relative path from the program
Get time series data from k-db.com in Python
Output the number of CPU cores in Python
Read the output of subprocess.Popen in real time
Output in the form of a python array
Output python execution time
Japanese output in Python
Visualize accelerometer information from the microcomputer board in real time with mbed + Python
Convert date timezone (time difference) in Python (from string)
Receive dictionary data from a Python program in AppleScript
Get standard output in real time with Python subprocess
Find the part that is 575 from Wikipedia in Python
[Python] How to output the list values in order
Find the difference in Python
Love was born in Python 2
Love was born in Python 3
Read Fortran output in python
Output "Draw ferns programmatically" to the drawing process in Python
Measure the execution result of the program in C ++, Java, Python.
Change the standard output destination to a file in Python
Sort and output the elements in the list as elements and multiples in Python.
[Understand in the shortest time] Python basics for data analysis
Get the value while specifying the default value from dict in Python
[Python] Display the elapsed time in hours, minutes, and seconds (00:00:00)
Get the current date and time in Python, considering the time difference
What beginners learned from the basics of variables in python
A Python program that aggregates time usage from icalendar data
Program to determine leap year from the Christian era [Python]
Determine the date and time format in Python and convert to Unixtime
Getting the arXiv API in Python
Output 2017 Premium Friday list in Python
I compared the calculation time of the moving average written in Python
Python in the browser: Brython's recommendation
Get data from Quandl in Python
Save the binary file in Python
Hit the Sesami API in Python
Get the desktop path in Python
Existence from the viewpoint of Python
Output the contents of ~ .xlsx in the folder to HTML with Python
Get the script path in Python
Read the standard output of a subprocess line by line in Python
Measure function execution time in Python
In the python command python points to python3.8
Implement the Singleton pattern in Python
Make standard output non-blocking in Python
Compatibility diagnosis program written in python
A function that measures the processing time of a method in python
Extract text from images in Python
Have python read the command output
Python (from first time to execution)
Hit the web API in Python
Time series plot started ~ python edition ~
Use the Flickr API from Python
See python for the first time
I wrote the queue in Python
Calculate the previous month in Python
Let's touch Google's Vision API from Python for the time being
Examine the object's class in python
Export and output files in Python