Solved

how can I insert time in my python script?

Posted on 2014-04-10
5
295 Views
Last Modified: 2014-04-11
I need to insert time in my deployment script. What command should i put so that i can get a total duration of time it took for the deployment? Means, i need to have the start time and end in my script and duration is took for the completed deployment process.

Any help will be appreciated.

Thanks much
Kewl
0
Comment
Question by:kewlclassic
  • 2
  • 2
5 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39991733
Assuming I understand what you are asking, then the time module should be what you are after. Specifically, the clock method:

e.g.

import time

time.clock()
# your code
executionTimeInSeconds = time.clock()
print(executionTimeInSeconds)

Open in new window

0
 
LVL 28

Expert Comment

by:pepr
ID: 39993698
@kaufmed: It seems that it can be used this way only on Windows. For Unix it seems that the two values should be subtracted. I did not try, but the doc says:
   On Unix, return the current processor time as a floating point number expressed in seconds. The precision, and in fact the very definition of the meaning of “processor time”, depends on that of the C function of the same name, but in any case, this is the function to use for benchmarking Python or timing algorithms.

    On Windows, this function returns wall-clock seconds elapsed since the first call to this function, as a floating point number, based on the Win32 function QueryPerformanceCounter(). The resolution is typically better than one microsecond.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39993897
I confess that I ran that code on Windows. When I started the code, I fully expected to have to subtract, but when I ran it, I (of course) noticed the Windows behavior. So I ran with it!

A good point to keep in consideration for sure  = )
0
 
LVL 28

Expert Comment

by:pepr
ID: 39994595
:) The  reason why I have noticed is that it was surprising for me. Because of that I have looked into the documentation. It is a bit strange that the function behaves that differently in both systems. The good thing is that it uses the QueryPerformanceCounter (i.e. high resolution).
0
 

Author Comment

by:kewlclassic
ID: 39995258
Thanks guys I appreciate your help on this.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question