The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 16, 2019, 05:13:28 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: php script execution time  (Read 3389 times)
jammaster82
Lifer
*****
Offline Offline

Posts: 666


Thats craigs list for ya


View Profile
« on: April 21, 2009, 04:11:48 PM »

Code:
   $time_start = microtime(true);
   //....
   //....
   //.... A billion sql queries that build $out
   //....
   //....
   $time_end = microtime(true);
   $time = $time_end - $time_start;
   
   $out= "This page took: $time seconds to create.<br>".$out;
   echo $out;


 ^----- So i create my pages like this and i just
got the following response:

Quote
This page took: -0.333816 seconds to create.

how could the ($time_end - $time_start)
be a negative number, ever?
Logged

The watched pot, never boils... But if you walk away from it , the soup burns.  What gives?
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #1 on: April 21, 2009, 05:40:57 PM »

Make sure you do the last call before any objects are destroyed. E.g. before any destructors are called.

If you register it as a global, you can get around this as by default, global unload functions fire after buffers are all flushed, etc.
Logged

hai
jammaster82
Lifer
*****
Offline Offline

Posts: 666


Thats craigs list for ya


View Profile
« Reply #2 on: April 21, 2009, 10:19:36 PM »

so registering it as a global will serialize the execution of
the two statements that assign the time?

Are all the command lines not parsed sequentially?

Im not too clear how this could be a possibility... How is php
handling the execution of this code here?

I can send you the code offline out of the eye of the world but its just
some file_get_contents statements in the shitload of
queries parts...

Is php not serializing each line of code but rather solving what it can of every line in different batches... this shouldnt happen if php works the way i think it does....
Logged

The watched pot, never boils... But if you walk away from it , the soup burns.  What gives?
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #3 on: April 21, 2009, 11:39:09 PM »

do you live in the southern hemisphere?
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
jammaster82
Lifer
*****
Offline Offline

Posts: 666


Thats craigs list for ya


View Profile
« Reply #4 on: April 22, 2009, 09:56:32 AM »

lol... no, are you suggesting this is like toilets that flush
backwards?  Seriously, how could the time end be greater
than the time start, anyone?
Logged

The watched pot, never boils... But if you walk away from it , the soup burns.  What gives?
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #5 on: April 22, 2009, 10:00:54 AM »

heh. lol

are you sure that none of those vars are being set in the big block?

try adding aaaaa to each of the vars in question, so you know thye are unique.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #6 on: April 22, 2009, 10:59:50 AM »

Use these, you'll be happier:

Code:
<?php

$start 
_microtime_float();
sleep(2);
echo(
_microtime_difference($start));

function 
_microtime_float()
{
list($usec$sec) = explode(' 'microtime());
return ((float)$usec + (float)$sec);
}

function 
_microtime_difference($startTime) { return _microtime_float() - $startTime; }
?>


The problem is the shape of microtime().
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
jammaster82
Lifer
*****
Offline Offline

Posts: 666


Thats craigs list for ya


View Profile
« Reply #7 on: April 22, 2009, 11:21:41 AM »

@nbs: what do you mean 'the big block'

@perkiset: Please elaborate on the 'shape' of microtime.. what
shape was my version in that yours is not?

the sleep(2) suggests to me this is doing an 'application.processmessages' type deal and that the
code is thrown NOT in order in all the little pieces... why
would you have to sleep(2) right there if not to 'spinmessageloop'
or something?

Logged

The watched pot, never boils... But if you walk away from it , the soup burns.  What gives?
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #8 on: April 22, 2009, 11:31:15 AM »

Dood, just echo microtime(). You'll see that it is actually a string with 2 parts, not a float as you'd expect. When you did the current - start, you subtracted only the first part of the string, not the second part, which is why you got the negative number.

sleep(2) was just for demonstration, nothing else. Nothing complicated about this at all. Code is absolutely in the order that you call it. The only exception is __destroy() handlers in classes and the closing handler for sessions, which will happen after your last line of code (unless you explicitly call them).
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #9 on: April 22, 2009, 01:17:38 PM »

oh yea... hahahahah LOL

this tripped me up many times, and probably still will considering I forgot its 2 parts.

basically your math is doing this:   4788123, 9817237 - 740572, 8792823 = crazyassrandomnumber
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
jammaster82
Lifer
*****
Offline Offline

Posts: 666


Thats craigs list for ya


View Profile
« Reply #10 on: April 22, 2009, 01:43:01 PM »

Excellent.  Thank you!

This other method of execution , what would it be called,

say for example you had a cloud/grid whatever multi
tiered setup.

Each participant was just waiting for a job to do and
then it would do its job and send the answer back to the
server ... (where serial execution wouldnt matter) I suppose
what im talking about is much like the SETI at home technology.

What is the term for this idea, Distributed Computing?

Logged

The watched pot, never boils... But if you walk away from it , the soup burns.  What gives?
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #11 on: April 22, 2009, 03:29:45 PM »

There are two different issues here.

Cloud computing essentially means it appears to you as one instance of an operating system - you are abstracted from the hardware that is actually executing your code. However the cloud still maintains the normal order and flow of your scripts. IsThisThingOn is big into the cloud.

Distributed computing is when you have a single application where some of the processing is done in JS at the client, some in PHP at the web server and some in MySQL stored procedures on the database (or the like) - it's when several different entities contribute to the application in their own idiom to get a job done. My systems are all currently huge into distributed. Java is also based on distributed in a big way.

You can do distributed processing among many clouds as well, which is also what ITTO is doing, although he's only into a single "slot" of the distributed app processing. In some ways, you could say that a mashup is a distributed cloud process.

The thought of holistic debugging for all of that just makes my head hurt.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #12 on: April 22, 2009, 04:04:20 PM »

cloud = many computers acting as 1, performing many applications.

distributed = 1 application using many separate computers to provide power for solving of individual pieces.
rendering 3d animations is an example of this. each frame is rendered on 1 machine at a time. speed is directly proportional to number of machines. and like you said, Seti@home is also.

clouds are technically made up of distributed systems, though even that is apparently becoming less true...
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
jammaster82
Lifer
*****
Offline Offline

Posts: 666


Thats craigs list for ya


View Profile
« Reply #13 on: April 27, 2009, 04:53:04 PM »

Use these, you'll be happier:

Code:
<?php

$start 
_microtime_float();
sleep(2);
echo(
_microtime_difference($start));

function 
_microtime_float()
{
list($usec$sec) = explode(' 'microtime());
return ((float)$usec + (float)$sec);
}

function 
_microtime_difference($startTime) { return _microtime_float() - $startTime; }
?>


The problem is the shape of microtime().

Im gonna come back to this cloud computing thing until
they freeze han solo... wait thats cloud city...

 Nerd

Okay, that is way too deep for me to go into right now, trying to get
back to this microtime difference... the result was:
Code:

  $time = _microtime_difference($time_start);

  $out= "This page took: $time seconds to create.<br>".$out;

Produces:

This page took: 1240875570.8299 seconds to create
// plus the rest of the page that was in $out


*****   how do i change that to a real amount of seconds?
Logged

The watched pot, never boils... But if you walk away from it , the soup burns.  What gives?
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #14 on: April 27, 2009, 05:04:09 PM »

Did you start with $time_start = _microtime_float()?

If you start with microtime() you'll get bad results.

Try this:
$start = _microtime_float();
// Do something here so you'll have some time to wait.
// If you sleep(1) you should see a difference of something like 1.0005.
$diff = _microtime_difference($start);
echo "Start: $start
Difference: $diff
";

« Last Edit: April 27, 2009, 05:05:54 PM by perkiset » Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!