|P is for Practical|
Word replace - notetab light vs perlby kiat (Vicar)
|on Oct 05, 2005 at 15:59 UTC||Need Help??|
Thought this was interesting...
I've a text file that has about 35 000 lines. Every line contains a word that I wanted to replace. I opened the file in NoteTab Light and conveniently used its Replace function to do the replacement. A total of 35 000 replacements were made. It took a while and that got me curious because I'm running Pentium 4 @ 3.20 GHz with 512 MB RAM.
I decided to time the process and found out that it took about 35 seconds - I had no idea how to time it automatically so I used an online stopwatch.
I was naturally curious how fast it would be done in Perl. Amazingly, Perl took
P.S: If I hadn't done it first in NoteTab Light, I wouldn't have any notion how "fast" Perl's 1 sec is.
Tried doing it in Notepad (the one that comes with Windows) and it hanged!
Modified my Perl code to count the number of replacements as well as added benchmarking:
Is there a better way to count the total number of replacements?