perl function times

ww‮figi.w‬tidea.com

The times function in Perl returns a list of four values that indicate the amount of system time and user time used by the current process and its children. Here's an example:

#!/usr/bin/perl

my $start = times();

# Do some heavy processing here
my $x = 0;
for (1..10000000) {
    $x += $_;
}

my $end = times();
my $elapsed = $end - $start;

print "Time elapsed: $elapsed seconds\n";

In this example, the times function is called twice to calculate the amount of time elapsed during the processing loop. The difference between the two times is calculated and printed as the elapsed time in seconds. The times function is often used in conjunction with the alarm function to implement timeouts for long-running processes.