in reply to Perl speed VS. other languages

It is my contention that Perl (once compiled) runs noticably faster than Java (obviously using similar code), at least on the machines I ran tests on (a 300mhz dual-CPU Ultrasparc workstation running Solaris 2.6 and a 700Mhz PC running NT 4.0 SP6a).

A consulting client had a web-page generated by Perl using CGI, and I re-implemented it in Java. There was a pure text manipulation part of the code (sorry, it was proprietary and I wasn't able to take it with me), which took about five seconds to produce an output web page using Perl 5.005_03 on Solaris 2.6.

The same thing, written as a Java 1.18 Servlet (under JServ 1.0, with Apache 1.3.2 on the same web server) also took five seconds to run and produce the results page.

If that sounds the same, note well that the Perl implementation was a vanilla CGI program (i.e., no mod_perl, FastCGI or the like), so that five seconds includes the standard Solaris process-startup delay plus the Perl startup/compile delay.

I would have loved to pursue this further, but unfortunately my contract ended first.

Replies are listed 'Best First'.
Re (tilly) 2: Perl speed VS. other languages
by tilly (Archbishop) on Jan 16, 2002 at 21:38 UTC
    5 seconds to produce a page?

    That doesn't sound to me like a language issue. It sounds like an algorithm issue or a bottleneck somewhere. I would start asking questions about rendering time in the browser, database connections, and the like.

    Unless, of course, there was something inherent in what it did that made 5 seconds seem like a reasonable amount of work to do...?

      Understand, this particular page was doing a huge amount of processing (a lot of nested loops) before producing results. The actual page generation was done after the processing, and was essentially a single print statement, e.g., print join( "\n", header, start_html, ..., end_html ), so there were no speed issues in that regard (trust me -- there might have been, but in this case there weren't).

      My point was that, after accounting for the process startup time, compile time, etc. of an otherwise standard CGI Perl program, the net run time was probably about three seconds (give or take a half second or so). In contrast, the Java Servlet implementing the same algorithm took roughly five seconds (also, give or take about a half second).

      In my opinion, Perl beats (non-JIT inlined) Java in raw performance.

        Well it is a known factoid: Perl compiles to high-level bytecode, ie many builtins compile to a single opcode, whereas Java bytecode mimics a real CPU, so you are essentialy pitting a P-code interpreter against a hardware emulator. The P-code is almost bound to win.

        The well known strategy of optimizing Perl programs by tuning them to spend a maximum amount of time running builtins (see Schwartzian Transform f.ex) highlights this issue clearly. Java optimization is very different and much closer resembles traditional optimization.