From: Mike Stok Date: 2002-09-17T21:13:26+09:00 Subject: Re: Java vs. Perl vs. ... In article , JamesBritt wrote: > The "Use Perl" website (use.perl.org) has a small entry commenting on a Java > vs. Perl test for performing string processing. The Perl site [1] says the > Java site [2] shows the Java source code for the match-up, but not the Perl > source. After some requests, the Java author released the Perl code to the > Perl folks (though it does not seem to have made it to the original Java > site). It's on the Perl site [1]. > > Not surprisingly, the Java site [2] claims the Java code is better, as it > ran the test case faster. > Also not surprisingly, the Perl folks believe the Perl code is really not > quality code and can be optimized to do better than Java. There are plenty of comments about the merits of the particular benchmark, but I was interested to see how Ruby stacks up on my machine. SO using Ruby 1.7.3 and Sun's Linux 1.4.0 JDK I tried the code on the Java site (plus the missing ") against #!/usr/bin/env ruby begin unless ARGV.length == 2 puts "Usage: #{$0} inputFile outputFile" exit 0 end start_time = Time.now File.open(ARGV[1], 'w') { |out| File.open(ARGV[0]).each_line { |line| unless ( line =~ /\.(?:css|jpg|gif|CSS|JPG|GIF) HTTP/ or line =~ /^192\.(9|18|29)\./) out.print(line) end } } end_time = Time.now puts "Processing time: #{end_time - start_time} Seconds" rescue => message puts "Error: #{message}" end [mike@ratdog tmp]$ time ruby CleanLogs.rb et-access.log xxx Processing time: 6.579613 Seconds 2.88user 0.16system 0:06.82elapsed 44%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (256major+431minor)pagefaults 0swaps [mike@ratdog tmp]$ time java CleanLogs et-access.log yyy Processing Time: 7 Seconds 4.07user 0.39system 0:10.45elapsed 42%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (1631major+1110minor)pagefaults 0swaps The outputs were identical, but as it was a quick between breakfast and walking the dog hack I may have missed something. :-) Mike -- mike@stok.co.uk | The "`Stok' disclaimers" apply. http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60 http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA