Solved

how can I insert time in my python script?

Posted on 2014-04-10
5
355 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
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 …

636 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