>>>>> "BT" == Ben Tilly <[EMAIL PROTECTED]> writes:

  BT> Secondly even in Perl I'd expect print to be faster than using .=
  BT> repeatedly instead of print.   Let's try it:

  BT> $ time perl -e 'print "hello world\n" for 1..1_000_000' > /dev/null

  BT> real    0m0.379s
  BT> user    0m0.380s
  BT> sys     0m0.000s

  BT> $ time perl -e '$s .= "hello world\n" for 1..1_000_000; print $s' > 
/dev/null

  BT> real    0m0.752s
  BT> user    0m0.600s
  BT> sys     0m0.150s

i will try that out and some other variations. size of the string being
appended is also an issue. also that is a very large amount of printing
and so the reallocating of the string buffer will hurt whereas the print
will just reuse the same buffer.
  >> use File::Slurp ;
  >> 
  >> my $text = do_lots_of_work_and_return_all_the_text() ;
  >> 
  >> print $text ;
  >> write_file( $tee_file, $text ) if $tee_file ;
  >> 
  >> it makes for a very good api too in all the other subs. most just return
  >> text and don't do any output themselves. then you can use the subs in
  >> any way you want, for output, sending a message, log entries,
  >> etc. printing at the point of text generation makes this impossible.

  BT> Maintainability is more important than optimization.  I often use
  BT> this strategy for maintainance reasons.  Going full-cycle, one way
  BT> to accomplish all of this without changing code is to tie to a
  BT> filehandle that accumulates data and prints it later.

but what if you don't want to print it but log it or send it to a
message? what if you want a status sub to be useful in many different
ways? making it use a handle or printing directly limits your
flexibility and control. delaying printing until you are ready also
means you can use write_file which is faster than print as it bypassed
perlio.

uri

-- 
Uri Guttman  ------  [EMAIL PROTECTED]  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to