In Perl:
my ($usr,$sys,$cusr,$csys) = times;
printf "real %s, user %s, sys %s\n", $usr + $sys, $usr, $sys;
Is this true? I read some other questions where people did things like saving the current time away in a variable and collecting it later, but why wouldn't this work?
No, it is not. User and system time account only for used CPU time. While the program is asleep, real time still passes, but the user and system time stand still. Also, on multi-CPU systems, it may well happen that user+system is greater than real time.
C:\Temp> cat tt.pl
sleep 5;
my ($user, $system) = times;
print "u = $user s = $system\n";
C:\Temp> tt
u = 0.015 s = 0.015
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With