Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how can I insert time in my python script?

Posted on 2014-04-10
5
Medium Priority
?
388 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 2000 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 29

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 29

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

971 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