473,671 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How much execution time is left?

I'm using set_time_limit( ) to set maximum execution time. Is there a
way to check how much time is left at any time during the execution
itself?
Feb 8 '08 #1
6 4547
Mikhail Kovalev wrote:
I'm using set_time_limit( ) to set maximum execution time. Is there a
way to check how much time is left at any time during the execution
itself?
Use time() or microtime() at the beginning of the script and store the
value. Later, call it again and substract the start time, you'll get the
elapsed time. Another substraction of the time limit by the elapsed time
will give you the remaining time.

-thib´
Feb 9 '08 #2
thib´ wrote:
Mikhail Kovalev wrote:
>I'm using set_time_limit( ) to set maximum execution time. Is there a
way to check how much time is left at any time during the execution
itself?

Use time() or microtime() at the beginning of the script and store the
value. Later, call it again and substract the start time, you'll get the
elapsed time. Another substraction of the time limit by the elapsed time
will give you the remaining time.

-thib´
Not true.

set_time_limit is the limit for execution time. time() or microtime()
is real time. A huge difference.

For instance - say you have a time limit of 30 seconds. One second into
your script, a high priority process gets invoked and runs for two minutes.

You still have about 29 seconds left left on your script, but the time()
or microtime() function says you're 1 minute, 31 seconds over.

An extreme example, I know. But it gets the point across.

So no, there is no way to tell how much time is left.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Feb 9 '08 #3
..oO(thib´)
>Mikhail Kovalev wrote:
>I'm using set_time_limit( ) to set maximum execution time. Is there a
way to check how much time is left at any time during the execution
itself?

Use time() or microtime() at the beginning of the script and store the
value. Later, call it again and substract the start time, you'll get the
elapsed time. Another substraction of the time limit by the elapsed time
will give you the remaining time.
This won't work. In addition to Jerry's example a quote from the manual:

| Note: The set_time_limit( ) function and the configuration directive
| max_execution_t ime only affect the execution time of the script
| itself. Any time spent on activity that happens outside the execution
| of the script such as system calls using system(), stream operations,
| database queries, etc. is not included when determining the maximum
| time that the script has been running.

Micha
Feb 9 '08 #4
Rob
On Feb 9, 3:42*pm, Michael Fesser <neti...@gmx.de wrote:
.oO(thib´)
Mikhail Kovalev wrote:
I'm using set_time_limit( ) to set maximum execution time. Is there a
way to check how much time is left at any time during the execution
itself?
Use time() or microtime() at the beginning of the script and store the
value. Later, call it again and substract the start time, you'll get the
elapsed time. Another substraction of the time limit by the elapsed time
will give you the remaining time.

This won't work. In addition to Jerry's example a quote from the manual:

| Note: The set_time_limit( ) function and the configuration directive
| max_execution_t ime only affect the execution time of the script
| itself. Any time spent on activity that happens outside the execution
| of the script such as system calls using system(), stream operations,
| database queries, etc. is not included when determining the maximum
| time that the script has been running.

Micha
True, but in general terms, Thib's solution should work - unless
Mikhail knows beforehand that there will be a lot of non-PHP
processing going on, i.e. file transfers.

Rob.
Feb 11 '08 #5
Michael Fesser wrote:
.oO(thib´)
>Mikhail Kovalev wrote:
>>I'm using set_time_limit( ) to set maximum execution time. Is there a
way to check how much time is left at any time during the execution
itself?
Use time() or microtime() at the beginning of the script and store the
value. Later, call it again and substract the start time, you'll get the
elapsed time. Another substraction of the time limit by the elapsed time
will give you the remaining time.

This won't work. In addition to Jerry's example a quote from the manual:

| Note: The set_time_limit( ) function and the configuration directive
| max_execution_t ime only affect the execution time of the script
| itself. Any time spent on activity that happens outside the execution
| of the script such as system calls using system(), stream operations,
| database queries, etc. is not included when determining the maximum
| time that the script has been running.

Micha
Good to know, thanks.

So, a not absolutely reliable way would be to stop the counter before every
'heavy' instruction and restart it again just after it, right?
I've seen some tiny handy "stopwatch" functions that could make the job
without too much complications.

Anyway, is it really worth it, Mikhail?

-thib´
Feb 13 '08 #6
There is a system resource call where PHP will admit how much system
time and user time has been used.

If you use lots of sleeps, freads, and cURLs, etc, you use very little
system time.

I have executed scripts on Godaddy websites [default CPU time 30
seconds] which are heavily waited, but the scripts are still
terminated after 15-20 minutes. I guess there is a dead-mans-handle.

Feb 19 '08 #7

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

Similar topics

6
3744
by: cournape | last post by:
Hi there, I have some scientific application written in python. There is a good deal of list processing, but also some "simple" computation such as basic linear algebra involved. I would like to speed things up implementing some of the functions in C. So I need profiling. I first tried to use the default python profiler, but profiling my application multiplies the execution time by a factor between 10 and 100 ! So I decided to give a...
5
2431
by: Johannes Lebek | last post by:
Hi there, lately, I experienced a strange thing on my DB2 V8.1 on Windows: Some queries took a very long time. A snapshot discovered the following: Number of executions = 47 Number of compilations = 1 Worst preparation time (ms) = 2 Best preparation time (ms) = 2 Internal rows deleted = 0
1
3706
by: UnixSlaxer | last post by:
Hello all, I installed the trial version of DB2 UDB 8.2, I was wondering, how can I determine the exact execution time (in miliseconds not timerons) for a specific query ? Thank you very much. Awaiting your response.
7
16082
by: Tim Quon | last post by:
Hi Is there any function to get the current time so I can calculate the execution time of my code? What all is in the time.h and sys/times.h? Thanks Tim
38
2549
by: vashwath | last post by:
Might be off topic but I don't know where to post this question.Hope some body clears my doubt. The coding standard of the project which I am working on say's not to use malloc.When I asked my lead(I have just started working) he said we should not use dynamic allocation in real time systems, the code will not run in predictable time period.Can anybody tell what does he mean?Why the execution time becomes unpredictable? Thanks
3
47810
by: iam980 | last post by:
Hello All. We have tested following SQL script from query analyzer: -- Script begin DECLARE @I int; SET @I = 1; WHILE @I < 10000000 BEGIN SET @I = @I + 1; END -- Script end
3
2186
by: vashwath | last post by:
Hi all, I have written program for calculating the execution time of a function.Any critics (on the method of calculating execution time) are welcome. #include <stdio.h> #include <time.h> #include <limits.h> #define DENO 10
6
1492
by: monkeyboy | last post by:
Hello, I have a function that hotshot says is very slow. I can get the aggregate execution time, but is there a way to get the execution time of each line so I can find the bottleneck? Thank you
25
5010
by: Umesh | last post by:
i want to calculate the time required to execute a program. Also i want to calcute the time remaining for the execution of the program. how can i do that? pl mention some good websites for learning advanced C.thx.
0
8392
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,...
0
8912
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
jinu1996
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...
1
8597
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,...
0
5692
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();...
0
4222
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...
0
4403
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2049
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1807
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.