View Full Version : Loading times...
fury
July 10th, 2001, 21:12
Hi all,
I was wondering if there is a script that would show loading times. You know how some webpages/scripts show at the bottom "Loaded in 0.0512 secs" or something like that. How would I go about implementing something like that?
Thanks :)
lucifer
July 11th, 2001, 04:41
I think they are time to generate page not load it.
easy
get system time at start of script.
do script
get system time at end
minus one from the other
print page generation .....ms
code depends on the language you use
Dusty
July 11th, 2001, 16:28
This would work for Perl and PHP:
$start_time=time();
# script here
$end_time=time();
print "Generated in ".($end_time-$start_time)." seconds";
fury
July 11th, 2001, 17:36
thanks very much for your help...
findftp
July 11th, 2001, 17:53
Originally posted by Dusty
This would work for Perl and PHP:
$start_time=time();
# script here
$end_time=time();
print "Generated in ".($end_time-$start_time)." seconds";
I've added it too!
But how about 3 decimals? is it something with printf?
If so,.. could you please give an example
atlas
July 11th, 2001, 18:01
This is for perl:
use Benchmark;
my $startBenchmark = new Benchmark;
...
your regular code here
...
my $endBenchmark = new Benchmark;
my $timeDiff = timediff($endBenchmark,$startBenchmark);
print "Took:" . timestr($timeDiff) . "\n\n";
There are more options for Benchmark, this is just one way of using it.
-mk
atlascgi.com
findftp
July 11th, 2001, 18:05
I tested it,.. got info about CPU too!
I only want time with 3 decimals
please
fury
July 11th, 2001, 19:45
yes I would like to know how to do this too...
thanks again for all the help..
findftp
July 12th, 2001, 05:37
anybody ?
lucifer
July 12th, 2001, 06:51
fprint sounds like the function your after
findftp
July 12th, 2001, 08:19
Originally posted by findftp
I've added it too!
But how about 3 decimals? is it something with printf?
If so,.. could you please give an example
That's what I already posted before. Could you please give an example?
niv
July 12th, 2001, 08:24
you mean it's giving you like 3.4680723723572345?
well make an integer $n = $timeseek * 1000 % 1000
then make a float $f = $n / 1000 + 0.000
fury
July 12th, 2001, 08:26
but is there a builtin way or function to do this?
niv
July 12th, 2001, 08:28
i wouldn't know. i'm an idiot.
findftp
July 12th, 2001, 09:16
This is what I use now. But the script tells me everytime that it took 0.295 seconds.
What's wrong?
This is the code
use Benchmark;
my $startBenchmark = new Benchmark;
##### rest of the script #####
my $endBenchmark = new Benchmark;
my $timeDiff = timediff($endBenchmark,$startBenchmark);
$n = ($timeDiff * 1000 % 1000);
$f = ($n / 1000 + 0.000);
$gtime = "<font size=\"-2\">Searched for: $f seconds</font>\n\n";
lucifer
July 12th, 2001, 10:32
you where using $timeDiff as a value which if you had printed you would see was something like 'Benchmark=ARRAY(0xbc53f0)' this was then being used to do some calcs
this works to 2 dp on my machine
use Benchmark;
my $startBenchmark = new Benchmark;
# wasting time
for ($i=0;$i<1000000;$i++){}
my $endBenchmark = new Benchmark;
my $timeDiff = timediff($endBenchmark,$startBenchmark);
$_=timestr($timeDiff);
/([\d\.]+) CPU/;
$f=$1;
print "<font size=\"-2\">Searched for: $f seconds</font>\n\n";
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.