views:

422

answers:

6

For programming tasks that need to be developed quick how does Perl compare to Java? How about as far as speed, would Perl be much slower than Java?

Whenever I need to program something quick I use Java. All the available libraries and built in goodness make Java pretty nice in my eyes. But there's a lot of people that swear by perl. In fact, I made a simple crawler a long time ago using Perl rather easily. So I'm considering learning Perl well.

Thanks.

+6  A: 

For quick and dirty jobs, Perl is definitely quicker to develop in. Execution speed is usually not much of an issue here anyway, but I doubt that Perl would be significantly slower than Java for most jobs. When you talk about "available libraries and built in goodness," Perl with CPAN also beats Java in convenience.

So, for the kind of programming job that I think you're talking about, Perl would be the better choice.

(My goodness... me... advocating Perl?)

Thomas
+1 for advocating Perl ;-)
Thorbjørn Ravn Andersen
I have written structures using Perl + stored procs, where a process spends a majority of time waiting for the SPs to return. And they can spit out 1000s of lines of data in fractions of a second.
Axeman
+5  A: 

It entirely depends on the task - and indeed your own expertise. I tend to use C# for quick and dirty tasks, but if I knew Perl, Ruby or Python as well as I knew C#, I suspect they'd be a better fit in many cases.

Both Perl and Java have a lot of libraries available. Perl works well for scripting and particularly text handling; Java may be more appropriate for larger, more complex systems.

As for performance, you'd have to benchmark the individual task... and consider trying it on Parrot as well.

Jon Skeet
+1 for Parrot and for a very complete answer
dfa
+5  A: 

Ah, I'm glad to see the question was re-opened.

So, here's an answer. If you are dealing mainly with text processing, it's difficult to achieve parity with, let alone surpass, Perl's performance. The whole language is designed around fast text processing. Furthermore, efficient string manipulation in Java is much more cumbersome -- codewise -- than in Perl.

Library-wise, Java hardly has an edge over Perl. Mostly, Java has an edge in the type of libraries which are useful for a language like Java, and Perl has an edge in the type of libraries which are useful for a language like Perl. So, a Java person, not knowing Perl, might look at what is available and detect some "deficiencies". The Perl person would not notice them, though, because they do things people don't do in Perl. And vice versa.

Another important point of Perl is that the boiler-plate level is low. It is low even among languages with low boiler-plate. You just can't compare it to Java in this respect.

And Perl is specially oriented towards scripting needs. For instance, if I write this:

#!/usr/bin/perl

while(<>) {
  m%//(.*)% && print $1;
}

I'm doing the following:

1. If there were arguments passed on the command line,
    1. For each argument passed on the command line
        1. Open the file with that name
        2. For each line of it
            1. If the line has a Java-style single-line comment,
                1. Print the comment
2. Otherwise,
    1. Open the stdin
    2. For each line of it
        1. If the line has a Java-style single-line comment,
            1. Print the comment

This means I can get working scripting code much faster with Perl than with most other languages. Which is a very important property if you often need a one-time-only script. Which is not the case of most people, but is certainly the case for some.

So, in that regard, Perl is certainly superior to Java. I won't bother enumerating the points in which Java is superior.

Daniel
Cool, thanks for the thorough answer. I was definitely wondering how perl's text processing compares to java (since that's what perl is known for). it seems like perl would be a good tool in my arsenal, especially as I creep into a job search.
Junier
+3  A: 

From mine experience Perl outperforms Java in IO tasks and dirty string operations. Java outperforms Perl in OOP overhead and special data-crunching, which is not covered by specialized Perl language construct or XS module. Perl also outperforms Java in productivity for dirty and near to death-line jobs.

Hynek -Pichi- Vychodil
+1  A: 

I'm both a Java programmer and a Perl programmer. In the past I used Perl for a number of "dirty jobs", mostly involing powerbrowsing (via LWP) and text handling. In my view Perl and Java share a huge user base (Perl mostly for sysadm) and therefore a large number of libraries and books. I like both very much, indeed I wish a javax.script's engine for Perl, a JPerl would be a killer feature for me.

dfa
+1 for JPerl advocacy.
Axeman
A: 

Slow and fast are a matter of platform. Java byte code--with hotspot and generations of early JIT developments in 1.2--is faster than Perl.

Nonetheless, Perl is fast enough for most things I've thrown at it. The scripts that I have written to do reporting and IO from the database spend most of their time (~70%) waiting for data from stored procedures that are as optimized as I can get them. When the data starts coming, thousands of lines--to dozens of files--can be processed in seconds. And when our smaller production Perl jobs are running, it's blink and you'll miss them.

But I have to go with the metrics that Java is faster than Perl, sometimes by orders of magnitude.

That's platform to "platform". (Perl isn't much of a platform, just a general specification of how to get the language to run on various machines.) But as a language, you just have to take a look at where most of the work was done in Java 5 and 6 (or even 1.4, with the addition of generics) to realize that it had been lacking as a language for some time. Now, they are even giving you other languages to work with, as long as you'll stay on Sun's platform.

Axeman