Solved

how can I insert time in my python script?

Posted on 2014-04-10
5
275 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 74

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 74

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

"The time has come," the Walrus said, "To talk of many things: Of sets--and lists--and dictionaries-- Of variable kinks-- And why you see it changing not-- And why so strange are strings." This part describes how variables and references (see …
Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
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…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now