Python Forum
python tool to collect the time measurement of entire code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python tool to collect the time measurement of entire code
#1
Hi Team,

Can any one suggest me that how to get the time measurement for entire lines of code and functions (each function wise)?

I am looking for the command line or tools

Regards,
Maiya
Reply
#2
Use profile The Python Profilers
Usually there a mixed of use of timeit, profile or 3-party libraries as eg line_profiler, SnakeViz
From notebook Profiling and Timing Code.
maiya likes this post
Reply
#3
As mentioned, the profile module has a command line interface:
python -m profile myfile.py
Reply
#4
Here is a decorator that will time the duration of any function. Just put @time_this_function right before whichever function you want to time.

def time_this_function (function_to_time) :
	from time import time

	def timer_wrapper (*args) :
		start_time = time ()
		function_to_time (*args)
		print ('\n\nThe function "' + function_to_time.__name__ +
			f' ()" required {time () - start_time:.5f} '
			'seconds to complete.')
	return timer_wrapper

@time_this_function
def show_many (text_string, count) :
	for number in range (count) :
		print(text_string, end = ' ')

show_many ('This is a test.', 99999)
maiya likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Make entire script run again every 45 mo NDillard 0 322 Jan-23-2024, 09:40 PM
Last Post: NDillard
  Trying to get year not the entire year & time mbrown009 2 888 Jan-09-2023, 01:46 PM
Last Post: snippsat
  How to change UTC time to local time in Python DataFrame? SamKnight 2 1,606 Jul-28-2022, 08:23 AM
Last Post: Pedroski55
  Is there software/tool for coding Python? dee 11 2,860 Jun-14-2022, 02:32 PM
Last Post: dee
  Reiszing figure to occupy entire frame fishbackp 0 1,375 Jan-06-2022, 10:33 PM
Last Post: fishbackp
  How to get OpenCV to display entire camera frame? George713 1 3,267 Aug-12-2021, 02:45 AM
Last Post: Pedroski55
  Assistance with running a few lines of code at an EXACT time nethatar 5 3,254 Feb-24-2021, 10:43 PM
Last Post: nilamo
  How to apply a class method to an entire dataframe column tirtha9 1 5,138 Jan-03-2021, 04:44 AM
Last Post: klllmmm
  Stumped by my own code (ratio & epoch-time calculation). MvGulik 2 2,143 Dec-30-2020, 12:04 AM
Last Post: MvGulik
  2d Array adds last element to entire list waiteup 2 2,090 Nov-19-2020, 08:25 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020