Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Word replace - notetab light vs perl

by Courage (Parson)
on Oct 06, 2005 at 14:41 UTC ( #497946=note: print w/replies, xml ) Need Help??


in reply to Word replace - notetab light vs perl

Your code could still be optimized to run two magnitudes faster.

If you'll match/replace entire contents as a string with a single s///g expression, instead of your "while" construct, you'll see dramatic speed increase.

You'll be surprised many times to see how fast Perl sometimes is....

Best regards,
Courage, the Cowardly Dog

  • Comment on Re: Word replace - notetab light vs perl

Replies are listed 'Best First'.
Re^2: Word replace - notetab light vs perl
by kiat (Vicar) on Oct 06, 2005 at 15:02 UTC
    Thanks, Courage :)

    Did you mean the following?

    use Benchmark; $start = new Benchmark; open(FH, "wrongs") or die $!; open(FH2, ">wrongs2") or die $!; undef $/; $lines = <FH>; $counted2 = $lines =~ s/wrongs/wrongs4/g; print FH2 "$lines"; $/ = "\n"; close (FH); close (FH2); $end = new Benchmark; # calculate difference $diff = timediff($end, $start); print "replaced: $counted2 The operation took: " , timestr($diff, 'all +');
      yes, you're fast to learn. :)
      regular expressions were speed-optimized a lot. Do RTFS a bit, and you'll have an idea on what I have in mind.

      A drawback of such optimization - no-one now can improve that code, because it is highly complicated.

      Well, this is not the only place on where perl has good speed abilities.

      Best regards,
      Courage, the Cowardly Dog

        Ilya has that general effect. :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://497946]
help
Chatterbox?
[marioroy]: Today, wanted to revisit running parallel Re: Crash with ForkManager on Windows. I tried running on Cygwin for comparison.
[marioroy]: Running parallel on Cygwin feels like running on Unix ;-)
[marioroy]: Fortunately, Strawberry Perl v5.26 runs well.
[karlgoethebier]: marioroy: He! Magic Mushrooms was a talk in the CB some days ago ;-)

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2017-09-23 16:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (272 votes). Check out past polls.

    Notices?