473,569 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Script Running Time

Hello,

I am trying to find a way to output how long a script took to run.

Obviously the print would go at the end of the script, so it would be
the time up till that point. I also run a PostgreSQL query inside the
script and would like to separately show how long the query took to
run.

Is this even possible?

Thanks,

Ewan
Feb 21 '08 #1
1 3437
I am trying to find a way to output how long a script took to run.
>
Obviously the print would go at the end of the script, so it would be
the time up till that point. I also run a PostgreSQL query inside the
script and would like to separately show how long the query took to
run.

Is this even possible?
Of course...depend ing on the resolution you need, you can do
something like

import datetime
start_script = datetime.dateti me.now()
# do stuff
start_postgresq l = datetime.dateti me.now()
# make your PG call
end_postgresql = datetime.dateti me.now()
# do remaining stuff
end_script = datetime.dateti me.now()
pg_time_taken = end_postgresql - start_postgresq l
script_time_tak en = end_script - start_script

You than have pg_time_taken and script_time_tak en (which are
timedelta objects) that you can use for whatever display purposes
you need.

Alternatively, you can use time.clock()

from time import clock
clock()
# do stuff
start_pg = clock()
# do pg stuff
end_pg = clock()
# rest of script
end_script = clock()
print "Your script took %i seconds" % end_script
print "Your PG took %i seconds" % (end_pg - start_pg)

-tkc

Feb 21 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
5386
by: Doug | last post by:
I have a script that does a huge database update, which takes a long time. However, the host I am running on (and I suspect most hosts) are running in "safe mode." This means I cannot change the maximum execution time of scripts. So, the script stops right in the middle of doing the update. On top of that, I am trying to make code that I...
4
2878
by: Damien Renwick | last post by:
I have a php script which simply stops midway through a while loop that processes records returned by a MySQL query. The HTML page continues trying to load the page but the php has stopped running and eventually I get a timeout. The script is running in my development environment which consists of php 4.3.4, Apache 1.3.28 and MySQL 4.0.17,...
2
2592
by: codesmithsf | last post by:
I'm using PHP 4.2.2 and Apache 2.0.4.0. A script running on a virtual host had an endless loop in it that brought Apache to its knees. I have max_execution_time=90 and memory_limit=32M to handle larger file uploads and Gallery stuff (thumbnail processing) but the script goes way past 90 seconds. Safe mode is off but the script doesn't...
3
3407
by: Pol | last post by:
Can php scripts be initiated as a cron jobs running indefinately in a loop performing a task? Any recommendations for writing a php script that will run as an unix server process that will run indefinitely once it starts? If cron starts it every 10 minutes. How can I check if I my process is running and then end if an instance is already...
11
3173
by: Hari Sekhon | last post by:
I have written a script and I would like to ensure that the script is never run more than once at any given time. What is the best way of testing and exiting if there is another version of this script running somewhere on this machine? I guess what I'm asking is how to handle system processes the way I can in shell. I am running this on...
13
5990
by: wattersmt | last post by:
Hello, I am trying to write a python cgi that calls a script over ssh, the problem is the script takes a very long time to execute so Apache makes the CGI time out and I never see any output. The script is set to print a progress report to stdout every 3 seconds but I never see any output until the child process is killed. Here's what I...
8
8812
by: Ulysse | last post by:
Hello, I have a python script which runs all the time (using of library threading). I would like this scipt to run on a remote linux Os using Putty. The problem is, when I close Putty command line window running on my Win PC, the python script stops to run too. I tried to use cron tables instead. By setting the time and restart cron...
9
2604
by: adamalton | last post by:
I've got a script which uses cURL to connect to another website, and it seems to be getting stuck (I can't quite figure out how, but that's besides the point!). The trouble is that when my script runs it redirects you to a "please wait" page, and it then executes by itself. So you can't click 'stop' in your browser to terminate the script. If...
5
3471
by: This | last post by:
I have a pretty basic emailing script that sends a relatively small number (150) of html emails. The emails are compiled, personalised from a mysql db subscribers list, and sent using mail() - after sending, a small summary html page is sent to the user with number sent, time taken and a simple navigation choice. Up to about 100 emails it...
1
47391
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or...
0
7703
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7681
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...
0
7983
tracyyun
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...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
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...
0
3662
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...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.