develooper Front page | | Postings from September 2002

Java v Perl dashing golf

Thread Next
September 17, 2002 07:09
Java v Perl dashing golf
Message ID:
I noticed a Java vs. Perl story on today.
claimed that a 100-line Java program was twice as fast as the
Perl equivalent, but did not publish said Perl equivalent.
Anyway, davorg got it from the author and here it is:

open(IN,$filename) || die "cannot open $ARGV[0] for reading: $!";
open(OUT,">$filename.out") || die "cannot open $filename.out for writing:
LINE: while(<IN>) {
    foreach $fileext (@fileext) {
        next LINE if ($_ =~ /$fileext HTTP/);
    foreach $sunIP (@sunIPs) {
        next LINE if ($_ =~ /^$sunIP/);
    print OUT;

I thought it might be interesting to golf this.

This is my best golf:

#!perl -n
/^192\.(9|18|29)\./|/(?i:gif|jpg|css) HTTP/||print

Curiously, this little golf program seems to flog the 15-line
original over the 100 meter dash too -- I would say the original
would be lucky to tortoise-crawl to the 25 meter line before the
golf program breasted the tape. Sorry, but I don't have proper
facilities to accurately do time comparisons right now.

I have not seriously tried the 100 meter dash, but this
one should be a little faster:

#!perl -n
/^192\.(?:9|18|29)\./||/(?i:gif|jpg|css) HTTP/ or print


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About