Perl is slow? How to make Perl execute code fast?
Here I am not going to give any lecture on how to make Perl execute your code faster. What I want to share with you is that Perl is not slow at processing text. As a novice to Perl, while writing a routine to process long text files, it happened that it executed code so fast (OK, so slow) that to process 500,000 (five hundred thousand) words I had to wait some 4 hours and 40 minutes. I was desperate that I had almost concluded that this is not a tool that can be of much use. I tried some search on the internet and found that the code to I had written to add elements to a hash was not similar to what I had coded by hit and trial. As a last resort I persuaded myself to change the code to look like the one on the Internet. Lo and behold, the same script now processed those 500,000 words in a few (10 or even less) seconds!
I used this script to find out the number of words that I had used over a period time and found that some 5,800 words I used. In my dad’s book, “Additives and Crystallization Processs: From Fundamental to Applications,” nearly (unique) 6,890 words were used. If you’d like to know how many words you used in a particular work, provide me with the text and I can give you the report for free.
Alternatively, you can buy my Perl script also.