Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Perl equivalent of unix time command

Reply
Thread Tools

Perl equivalent of unix time command

 
 
Melroy
Guest
Posts: n/a
 
      09-07-2008
Hi all,
I want to benchmark a bunch of running processes using Perl , but I
could not find any equivalent for the unix time coammnd in perl? Can
someone point to me
if such a function exists in perl? The only command I found was
"times",
but I don't know how to use it. doing a websearch did not help. If the
function
"times" does teh job, can someone show me an example of how to use it?

Thanks
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      09-07-2008
Melroy <(E-Mail Removed)> wrote:
>I want to benchmark a bunch of running processes using Perl ,


You may want to check 'perldoc -q profile':
How do I profile my Perl programs?

> but I
>could not find any equivalent for the unix time coammnd in perl? Can
>someone point to me
>if such a function exists in perl?


There can't be an exact equivalent, because Unix time reports the total
time _AFTER_ the process has already terminated while in Perl the script
would still be running when you are executing the time check. So at best
it can report the elapsed time of the script until now.

>The only command I found was
>"times",
>but I don't know how to use it.


You may want to check the documentation: perldoc -f times

jue
 
Reply With Quote
 
 
 
 
Melroy
Guest
Posts: n/a
 
      09-07-2008
Hi,
I want to profile a bunch of command line programs using perl. I tried
to call the unix
time comamnd using backslash as well as the system comamnd but that
does not seem to capture the output. So i thought to check if there is
something native to perl.
Thanks

> You may want to check 'perldoc -q profile':
> * * * * * How do I profile my Perl programs?
>
> > but I
> >could not find any equivalent for the unix time coammnd in perl? Can
> >someone point to me
> >if such a function exists in perl?

>
> There can't be an exact equivalent, because Unix time reports the total
> time _AFTER_ the process has already terminated while in Perl the script
> would still be running when you are executing the time check. So at best
> it can report the elapsed time of the script until now.
>
> >The only command I found was
> >"times",
> >but I don't know how to use it.

>
> You may want to check the documentation: perldoc -f times
>
> jue


 
Reply With Quote
 
Melroy
Guest
Posts: n/a
 
      09-07-2008
More speccifically here is what I tried following
http://bytes.com/forum/thread678672.html
but no use

my $v = `time -p gzip energylossmc.dat 1>/dev/null 2>&1` ;
print $v ;
Nothing seems to get captured in the variable v?
What am I doing wrong?
I also replaced time with /usr/bin/time
but no use.

Any help is greatly appreciated
 
Reply With Quote
 
Randal L. Schwartz
Guest
Posts: n/a
 
      09-07-2008
>>>>> "Melroy" == Melroy <(E-Mail Removed)> writes:

Melroy> my $v = `time -p gzip energylossmc.dat 1>/dev/null 2>&1` ;
Melroy> print $v ;

Yes. You've just said "make stdout go to dev null instead of being
copied to the variable, and while you're at it, make stderr also go
there too".

Why would you expect anything to be in $v after this?

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<(E-Mail Removed)> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
 
Reply With Quote
 
Sherm Pendley
Guest
Posts: n/a
 
      09-08-2008
Melroy <(E-Mail Removed)> writes:

> my $v = `time -p gzip energylossmc.dat 1>/dev/null 2>&1` ;
> print $v ;
> Nothing seems to get captured in the variable v?


Your shell command redirects both stdout and stderr to /dev/null, so
there's nothing to capture.

sherm--

--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      09-08-2008
[Please do not top-post. It interrupts the normal flow of reading and
leaves people wondering which part of a message your comments are
referring to.]

Melroy <(E-Mail Removed)> wrote:
>> You may want to check 'perldoc -q profile':
>> * * * * * How do I profile my Perl programs?


>I want to profile a bunch of command line programs using perl. I tried
>to call the unix


Sorry, then I misunderstood your original request.

>time comamnd using backslash as well as the system comamnd but that
>does not seem to capture the output. So i thought to check if there is
>something native to perl.



Backslash? Could you post an actual code sample?

As for system(): it is not supposed to capture any output, please see
third paragraph, third sentence of the documentation of system().

jue
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      09-08-2008
Melroy <(E-Mail Removed)> wrote:
>my $v = `time -p gzip energylossmc.dat 1>/dev/null 2>&1` ;
>print $v ;
>Nothing seems to get captured in the variable v?
>What am I doing wrong?


My shell skills are somewhat rusty, but I think you are redirecting
stdin as well as stdout to /dev/null.
And aside of those two there simply is nothing else that could possibly
be outputted by the command and captured in $v.

jue
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      09-08-2008
Jürgen Exner <(E-Mail Removed)> wrote:
>Melroy <(E-Mail Removed)> wrote:
>>my $v = `time -p gzip energylossmc.dat 1>/dev/null 2>&1` ;
>>print $v ;
>>Nothing seems to get captured in the variable v?
>>What am I doing wrong?

>
>My shell skills are somewhat rusty, but I think you are redirecting
>stdin as well as stdout to /dev/null.


Daaaah! Make that STDOUT and STDERR, of course.

>And aside of those two there simply is nothing else that could possibly
>be outputted by the command and captured in $v.
>
>jue

 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      09-08-2008
Melroy <(E-Mail Removed)> wrote:
> Hi all,
> I want to benchmark a bunch of running processes using Perl ,


Why?

> but I
> could not find any equivalent for the unix time coammnd in perl?


system "time $process @args" ....;


Can
> someone point to me
> if such a function exists in perl? The only command I found was
> "times",
> but I don't know how to use it.


Capture the value before the external program is run, capture again
after, and subtract.


> doing a websearch did not help. If the
> function
> "times" does teh job, can someone show me an example of how to use it?


$ perl -l
my @x= times;
system q{perl -le '1 foreach (1..1e7)'};
my $i;
foreach( times) {
print $_ - $x[$i++]
}
__END__
0
0
0.57
0

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Equivalent for unix "read" command in rake tasks? Rob Lucas Ruby 9 12-09-2007 07:10 AM
Pure Python equivalent of unix "file" command? W3 Python 2 07-23-2007 12:40 PM
C Program [ Turbo-C ] , to extract only-Printable-characters from a file ( any type of file) and display them ( i.e equivalent to "strings" command in UNIX) SunRise C Programming 7 07-06-2005 08:11 AM
C Program [ Turbo-C ] , to extract only-Printable-characters from a file ( any type of file) and display them ( i.e equivalent to "strings" command in UNIX) SunRise C Programming 2 07-02-2005 11:35 PM
HELP: Python equivalent of UNIX command "touch" pekka niiranen Python 5 03-03-2005 09:23 AM



Advertisments