| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| 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 |
|
#2
| |||
| |||
| Melroy <melroysoares@hotmail.com> 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 |
|
#3
| |||
| |||
| 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 |
|
#4
| |||
| |||
| 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 |
|
#5
| |||
| |||
| >>>>> "Melroy" == Melroy <melroysoares@hotmail.com> 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 <merlyn@stonehenge.com> <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 |
|
#6
| |||
| |||
| Melroy <melroysoares@hotmail.com> 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 |
|
#7
| |||
| |||
| [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 <melroysoares@hotmail.com> 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 |
|
#8
| |||
| |||
| Melroy <melroysoares@hotmail.com> 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 |
|
#9
| |||
| |||
| Jürgen Exner <jurgenex@hotmail.com> wrote: >Melroy <melroysoares@hotmail.com> 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 |
|
#10
| |||
| |||
| Melroy <melroysoares@hotmail.com> 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. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.