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 6249
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
>>> import socket
>>> s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
>>> s.bind(('localhost',9000))
|
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 script and then wait until all
subprocesses have completed before continuing. The subprocesses run on
other machines ie this is a coarse grained parallel computation task.
So the commands I am using are:
for x in range(0, limit):
os.system("xgrid...
|
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 runs fine for a
while, but eventually slows down to a crawl. Running sar shows that
when it is running slowly there is an exceptionally large number of
minor page faults - there are continuously 14000 faults/sec, with a
variation of about...
|
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 something). I have
already learned how to do a "progress bar" type solution, which lets
me calculate percentages. This is different however, because rate
implies time.
I've tried making a timer that goes off once a second and then
applying (bytes...
|
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) {/* parent process */
pid2 = fork();
| |
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
FSUM utility died in a file with unicode filename... (It is unknown
error: I used alternate file name, but it not found).
|
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 return from wait
even though the subprocess that finished was created by another thread
thats also waiting.
i.e. - 2 threads, each thread opens a subprocess and waits. The
subprocess created by thread 1 has ended and thread 2 is released from...
|
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
scanner and not need to touch the mouse or keyboard. i can
successfully clock in but i am havin difficulties when it comes to
clocking out i am no good with VBA code but if anyone could help me
with if true statements or other ways to produce...
|
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 and the second one contains the field for the time they are leaving (timeout)
My problem is that I don’t know how to connect these two tables in the query to show the results and make the calculations need for the total working time for every...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |