Re: Counting the time with fractions of a second. The solution!

2002-07-15 Thread perl-dvd

Teddy,
Because times is a perl function, not necessarily a var.  Here's what one of my 
perl books has
to say about it:
---
The times function returns the amount of job time consumed by this program and any 
child processes
of this program.

The syntax for the times function is

@timelist = times

As you can see, times accepts no arguments.  It returns a list consisting of the 
following four
floating-point numbers:
- The user time consumed by this program
- The system time consumed by this program
- The user time consumed by the child processes, if they exist
- The system time consumed by the child processes, if they exist
---
So there you have it.  When you are calling $begin = (times)[0];  You are calling 
times function
and specifying that you only want to get back the first element of the returned array, 
which happens
to be the "user time consumed".

Regards,
David




- Original Message -
From: "Octavian Rasnita" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, July 13, 2002 11:27 AM
Subject: Counting the time with fractions of a second. The solution!


Hi all,

I found the easiest solution (until now)  for calculating how much time a
script runs.
Thank you for other solutions, but they are too complicated.

Here is the code you should use for calculating the time a script runs:

my $start = (times)[0];

#Here goes the script.

my $end = (times)[0];
my $duration = $end - $start;
print "The script ran for $duration seconds";

This will print the duration in fractions of a second like 1.012, etc.

This method doesn't require any module.

I've used a more simple method a few months ago, but I don't remember it.

I don't understand why (times)[0], but it works.
I've tried putting $times[0] and if I use it only for finding the start
time, it works, but if I use it for the start and the end time, it doesn't
work.

Can you make some light?

Thank you very much.

Teddy Center: http://teddy.fcc.ro/
Mail: [EMAIL PROTECTED]



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Counting the time with fractions of a second. The solution!

2002-07-13 Thread Octavian Rasnita

Hi all,

I found the easiest solution (until now)  for calculating how much time a
script runs.
Thank you for other solutions, but they are too complicated.

Here is the code you should use for calculating the time a script runs:

my $start = (times)[0];

#Here goes the script.

my $end = (times)[0];
my $duration = $end - $start;
print "The script ran for $duration seconds";

This will print the duration in fractions of a second like 1.012, etc.

This method doesn't require any module.

I've used a more simple method a few months ago, but I don't remember it.

I don't understand why (times)[0], but it works.
I've tried putting $times[0] and if I use it only for finding the start
time, it works, but if I use it for the start and the end time, it doesn't
work.

Can you make some light?

Thank you very much.

Teddy Center: http://teddy.fcc.ro/
Mail: [EMAIL PROTECTED]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]