Some days ago my boss asked me to write a script to process some text files to another format. Just a little bit of regular expressions. Nothing serious. Normally I would do this probably in Perl, but he expected me to do it all in JavaScript to run inside a Windows Script Host.
So after a bit of coding, I’ve written this script. It was splitting lines of text with a fixed length of fields to a coma-separated lines. It was also trimming the whitespaces and reformatting some numbers. Nothing special as I’ve said.
Everyone says, that JavaScript would do this extremely slow, so I have also created a similar Perl script just to compare performance. I can say that I write well both in Perl and JavaScript (Jscript in this case), so I wasn’t comparing bad JavaScript to good one written in Perl, and vice versa.
After that I’ve fired both scripts and measured timings. Test data file was big enough – about 450 thousands of records giving 150 megabytes of data. I’ll write how to measure timing of the script or console application execution in next post.
The results confirmed that JavaScript is much slower than Perl. Perl script processed the data in bout 48 seconds on my machine. JavaScript version needed 66 seconds (the same result as in Perl). In JavaScript version I’ve also added some extra operations which takes extra 60 seconds. In Perl those changes added just 20 seconds. So, yes – Perl is faster. But in real word I wont process such a big data files. Script will rocess just a few files a week and the wiles wont be bigger than about 30 – 40 megabytes. Although the Perl version is faster, JavaScript is fast enough to meet our needs. It is also easy to write and needs no extra software on Windows.
No comments:
Post a Comment