home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / perl / 4992 < prev    next >
Encoding:
Text File  |  1992-07-28  |  1.8 KB  |  48 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!msdrl!ball
  3. From: ball@msdrl.com (Richard Ball)
  4. Subject: too slowwww.....
  5. Message-ID: <1992Jul28.130015.23389@msdrl.com>
  6. Organization: Merck Research Laboratories
  7. Date: Tue, 28 Jul 92 13:00:15 GMT
  8. Lines: 38
  9.  
  10. (My apologies if this is a repost (someone please let me know if it is) but
  11.  news was a liile flakey and I'm not sure if this got out. The following is
  12.  the gist of my question)
  13.  
  14. After learning a little perl I thought I would apply it to a task I had in
  15. reformatting a postscript file. My filter, not surprisingly I guess, runs very
  16. slowly and since there are a few here with interests in speed and scalability I
  17. would like to solicit suggestions for improvement. I am mchanging a file from
  18.        this                                     to this
  19.  5.939 u  6.001 u mt                         427.6 432.1 m
  20.  4.002 u  3.221 u lt                         288.1 231.9 l
  21. [ with lots more lt type lines]              [etc]
  22. s                                            S
  23.  7.845 u 1.669 u mt                          564.8 120.2 m
  24. [etc., etc.]                                 [etc., etc.]
  25.  
  26. file size is about 9 or 10 K lines. 
  27.  
  28. The guts of my script are:
  29. while (<STDIN>){
  30.   if (/^s/) {print "S\n"; next;}
  31.   tr/u//d;
  32.   ($x, $y, $mode) = split(' ');
  33.   chop($mode);
  34.   $x = $x * 72;
  35.   $y = $y * 72;
  36.   printf "%6.1f %6.1f $s\n", $x, $y, $mode;
  37. }
  38.  
  39. But this takes almost a minute on an 8K line file! From some testing its clear
  40. the split and the printf are the worst time hogs. I want the effects of the
  41. printf though so I only get 1 decimal place on the output. 
  42. Anyone got any tricks that will get the time down?
  43.  
  44. R.G. Ball                    |  phone: 908-594-5341
  45. Merck Research Laboratories  |  FAX:   908-594-6645
  46. PO Box 2000, MD:RY80N-18A    |  email: ball@msdrl.com
  47. Rahway, NJ 07065  USA        |    or   ...!uunet!msdrl!ball
  48.