Skip to content
Fix Code Error

How do I get time of a Python program’s execution?

March 13, 2021 by Code Error
Posted By: Anonymous

I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.

I’ve looked at the timeit module, but it seems it’s only for small snippets of code. I want to time the whole program.

Solution

The simplest way in Python:

import time
start_time = time.time()
main()
print("--- %s seconds ---" % (time.time() - start_time))

This assumes that your program takes at least a tenth of second to run.

Prints:

--- 0.764891862869 seconds ---
Answered By: Anonymous

Related Articles

  • Gradle error: Execution failed for task…
  • org.gradle.api.tasks.TaskExecutionException:…
  • Returning the product of a list
  • What is %timeit in python?
  • Python is not calling fucntions properly
  • Execution failed for task…
  • How to get all of the immediate subdirectories in Python
  • Beautiful way to remove GET-variables with PHP?
  • How do I obtain a Query Execution Plan in SQL Server?
  • How to subtract 2 timestamp (one as a date, other in…
  • Create random list of integers in Python
  • What does if __name__ == "__main__": do?
  • OperationalError, no such column. Django
  • Updating state on props change in React Form
  • Android- Error:Execution failed for task…
  • [] and {} vs list() and dict(), which is better?
  • What makes the different performances between…
  • How do I append one string to another in Python?
  • Individual click handlers in v-for loop
  • Can Python test the membership of multiple values in a list?
  • What are the undocumented features and limitations…
  • Gradle: Execution failed for task ':processDebugManifest'
  • What's the difference between eval, exec, and compile?
  • How do I measure execution time of a command on the…
  • What is your most productive shortcut with Vim?
  • Running a cron every 30 seconds
  • Python File Error: unpack requires a buffer of 16 bytes
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • How do I convert datetime.timedelta to minutes,…
  • Filter by partition in Snowflake
  • Error:Execution failed for task…
  • Best way to strip punctuation from a string
  • TypeError: cannot convert the series to in to_date
  • How to use timeit module
  • Python: importing a sub‑package or sub‑module
  • Python strip() multiple characters?
  • Relative imports for the billionth time
  • Can't install via pip because of egg_info error
  • Ruby On Rails PG Database problem using nested form…
  • Exception : AAPT2 error: check logs for details
  • How can I time a code segment for testing…
  • Start redis-server with config file
  • Is .isin() faster than .query()
  • The simplest possible JavaScript countdown timer?
  • How to use html template with vue.js
  • Fast check for NaN in NumPy
  • Simplest way to create Unix-like continuous pipeline…
  • Pandas create the new columns based on the distinct…
  • Usage of __slots__?
  • Eclipse will not start and I haven't changed anything
  • Get a random boolean in python?
  • i have this error what is the solve for it
  • Why is there no xrange function in Python3?
  • Efficient Algorithm for Bit Reversal (from…
  • When I'm testing a web app by JUnit and Mockito I…
  • How to add Typescript to a Nativescript-Vue project?
  • Import Python Script Into Another?
  • How to sleep a process when using multiprocessing in…
  • How to VueJS router-link active style
  • How to combine the data from two different…
  • How to solve Internal Server Error in Next.Js?
  • Importing a function from a class in another file?
  • Why does C++ code for testing the Collatz conjecture…
  • Why do git fetch origin and git fetch : behave differently?
  • How to set timer in android?
  • How to convert a string of bytes into an int?
  • Multiprocessing only utilizing a single core
  • How can I find the product GUID of an installed MSI setup?
  • VUE Error when run test unit
  • How do I print colored output to the terminal in Python?
  • Vue&TypeScript: how to avoid error TS2345 when…
  • I do not use TBB, but I get linker errors related to TBB
  • How to stop a command on only one server discord.py?
  • Is it possible to use argsort in descending order?
  • Improve INSERT-per-second performance of SQLite
  • How do I filter for data that has partially matching…
  • PySpark 3 - UDF to remove items from list column
  • How to avoid "module not found" error while calling…
  • Why is reading lines from stdin much slower in C++…
  • python to arduino serial read & write
  • Webpack command throws error: Cannot find module 'webpack'
  • Create list of single item repeated N times
  • Sum the digits of a number
  • Byte Array to Hex String
  • Why is the resulting video half the time long, when…
  • Finding the index of an item in a list
  • Tkinter understanding mainloop
  • ExpressJS How to structure an application?
  • Timeout a command in bash without unnecessary delay
  • Training Word2Vec Model from sourced data - Issue…
  • Android app unable to start activity componentinfo
  • Hive/SQL Error when converting milliseconds to DDDD:HH:mm:ss
  • Problem when reloading page using react-router-dom
  • How do you calculate program run time in python?
  • Ubuntu apt-get unable to fetch packages
  • TypeError: apriori() got an unexpected keyword…
  • How to scrape all the pages in the website
  • Mock MQRFH2 header in JUnit Testing Error [MQRFH2…
  • How do I merge two dictionaries in a single…
  • How can I solve " Invalid datetime format: 1366…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How do you auto format code in Visual Studio?

Next Post:

How do I disable the resizable property of a textarea?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error