Hi,
I've seen several threads on this subject, but haven't (yet) run
across one that answers my specific questions. This should be really
easy for someone, so here goes:
I'm running some numerical simulations under Ubuntu, and using Python
as my scripting language to automatically manage input and output. I
need to have a precise performance measurement (CPU time) of how long
it takes to run my simulations.
Right now I have something like:
stime = time.time()
subprocess.call(["./mysim","args"])
ftime = time.time()
print ftime-stime
However, time.time() only gives wall-clock time, so I'm also measuring
the time it takes to run other processes running at the same time.
What I'd rather have is:
stime = time.clock()
subprocess.call(["./mysim","args"])
ftime = time.clock()
print ftime-stime
But this, of course, usually outputs 0, because time.clock() does not
count the CPU ticks of the subprocess.
So, long story short, I need to get CPU time of something I call using
subprocess.call(). I don't want to have to profile my code, since it
will significantly reduce computation time.
Thanks for the advice.
Kevin 3 6226
On Mar 3, 11:57*am, barnbu...@gmail.com wrote:
So, long story short, I need to get CPU time of something I call using
subprocess.call(). *
Run your command through the "time" program. You can parse the output
format of "time", or set a custom output format. This mostly applies
to Unix-like systems but there is probably an equivalent somewhere on
Windows.
Preston
On Mar 3, 12:41 pm, Preston Landers <pland...@gmail.comwrote:
>
Run your command through the "time" program. You can parse the output
format of "time", or set a custom output format. This mostly applies
to Unix-like systems but there is probably an equivalent somewhere on
Windows.
Preston
Thanks for the quick answer. That seems to work, though, I'll write a
timesubprocess() function which runs the program through time and
spits the formatted out to a file, then parses that file, then returns
the execution time. There doesn't appear to be a more elegant way to
do this.
Kevin
On Mar 3, 9:57 am, barnbu...@gmail.com wrote:
Hi,
I've seen several threads on this subject, but haven't (yet) run
across one that answers my specific questions. This should be really
easy for someone, so here goes:
I'm running some numerical simulations under Ubuntu, and using Python
as my scripting language to automatically manage input and output. I
need to have a precise performance measurement (CPU time) of how long
it takes to run my simulations.
Right now I have something like:
stime = time.time()
subprocess.call(["./mysim","args"])
ftime = time.time()
print ftime-stime
However, time.time() only gives wall-clock time, so I'm also measuring
the time it takes to run other processes running at the same time.
What I'd rather have is:
stime = time.clock()
subprocess.call(["./mysim","args"])
ftime = time.clock()
print ftime-stime
But this, of course, usually outputs 0, because time.clock() does not
count the CPU ticks of the subprocess.
So, long story short, I need to get CPU time of something I call using
subprocess.call(). I don't want to have to profile my code, since it
will significantly reduce computation time.
Use os.times(). It returns a 5-tuple and what you want is child cpu
times.
times(...)
times() -(utime, stime, cutime, cstime, elapsed_time)
Return a tuple of floating point numbers indicating process times.
cutime+cstime will give you the total CPU used by child (your
simulation).
Karthik
>
Thanks for the advice.
Kevin
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jane Austine |
last post by:
Running Python 2.3 on Win XP
It seems like socket is working interdependently with subprocesses of
the process which created socket.
------------------------------------
#the server side
>>>...
|
by: Marcos |
last post by:
Hi guys,
I realise this question has been answered in one form or another many
times before but I can't quite find the solution I need. I am trying to
run multiple subprocesses from a python...
|
by: Dave Kirby |
last post by:
I am working on a network management program written in python that has
multiple threads (typically 20+) spawning subprocesses which are used
to communicate with other systems on the network. This...
|
by: None |
last post by:
I'm using the HttpWebRequest/Response methods and I'm trying to figure
out how to calculate the effective transfer rare the file is being
received at (like you see in IE when you download...
|
by: babis85 |
last post by:
Hello guys, i have this part of code and i want to compute the time of
processes A, B and C :
/* process A */
pid_t pid1, pid2, pid;
struct rusage ru1, ru2;
pid1 = fork();
if (pid != 0) {/*...
|
by: Dara Durum |
last post by:
Hi !
Py2.4, Win32.
I need to optimize a program that have a speciality: hash (MD5/SHA1)
the file contents (many files).
Now I do this in a simple python program, because (what a pity) the...
|
by: Gal Diskin |
last post by:
Hi all,
I'm writing a python program using threads to open several subprocesses
concurrently (using module subprocess) and wait on them. I was
wondering if there is a possibilty that a thread will...
|
by: madgunnercurz |
last post by:
i currently have a database for tracking members arrival and exit
times. however due to new demands my training centre are wanting a
barcode system setup where all the user has to do is use a wedge...
|
by: anchamal |
last post by:
I’m using Ms Access 2003 and I have this problem in the query,
I created two tables named timein and timeout. The first one contains the time field that the employees are coming (timein) to work...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |