in reply to Re: Your favorite objects NOT of the hashref phylum
in thread Your favorite objects NOT of the hashref phylum

How about just using the builtin Perl function time instead of backticks and the unix date function?

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

  • Comment on Re^2: Your favorite objects NOT of the hashref phylum

Replies are listed 'Best First'.
Re^3: Your favorite objects NOT of the hashref phylum
by codeacrobat (Chaplain) on Mar 23, 2006 at 17:18 UTC
    Thanx, sometimes I forget the simplest things. I just needed a quick example illustrating the Stopwatch. I guess the reason I forgot about time is that there are so many similar functions (time, times, gmtime, localtime, asctime, mktime, andwhatnottime).
    It's good to have the backticks if you got lost but know a non-perl alternative.
      Thanx, sometimes I forget the simplest things

      Me, too. Sometimes, I find there's nothing for it but a good skim through perlfunc, which has a nicely categorized list of all the built-in functions (and has all the long descriptions that perldoc -f gives you).

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

        perlfunc is a fine thing. I prefer searching it directly over using for example perldoc -f time. You can always hit /^\s+time and then n some times until you find the function record.
        This is slower and sometimes you have to hit n a couple of times. The good thing is you learn/remember the rest of the functions.
Re^3: Your favorite objects NOT of the hashref phylum
by Anonymous Monk on Mar 25, 2006 at 12:07 UTC
    I remember using date in a log function once as a Perl junior. I finally noticed it because my code was taking a while to run, so I did my first ever profiling run on it. The backtick date was consuming 60% of the CPU time for the entire process.
      It looks like it is more than 60% (cygwin, samsung x25). It does not matter whether you use backticks or a regular open to the date program, both are equally slow.
      $ time perl -e 'do {open PROGRAM, "date +%s|" or die "can not open dat +e $!";$time = <PROGRAM>;close PROGRAM} for 0 .. 1000' real 0m14.733s user 0m32.927s sys 0m9.109s $ time perl -e 'do { $time = `date +%s`} for 0 .. 1000' real 0m14.717s user 0m32.929s sys 0m9.138s $ time perl -e 'do { $time = time} for 0 .. 1000' real 0m0.084s user 0m0.061s sys 0m0.046s