Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Perl slower than java

by dHarry (Abbot)
on Dec 09, 2010 at 11:09 UTC ( [id://876235]=note: print w/replies, xml ) Need Help??


in reply to Perl slower than java

I hate to disappoint you but Java is pretty fast nowadays. Many clever optimizations have improved the performance of the Java Virtual Machine. Although startup is typically slower than other languages and Java programs tend to be more memory hungry many benchmarks show that for many types of tasks the performance is close to that of C++. So although you can optimize/improve your perl script, in ways others have suggested, I doubt you can really beat the Java implementation in terms of execution speed. Also, it's not unthinkable your java program can't be optimized. If you really want speed C is probably the best choice (unless you like assembler;). I typically use Perl to prototype solutions because I can do that (much) faster compared to other languages. Normally I re-implement in Java and when speed is essential in C.

Cheers

Harry

PS I'm working on CSP's and looking into Genetic Algorithms for solving them, well, approaching a decent solution in less time than other algorithms take. I know of several open source Java implementations, I wonder why you wrote it yourself? Would you care to share your code?

Replies are listed 'Best First'.
Re^2: Perl slower than java
by anonymized user 468275 (Curate) on Dec 09, 2010 at 11:29 UTC
    Even with the fastest possible machine and language, performance-aware algorithm design usually makes more difference. To take an extreme case, I once rewrote a C-program (which is faster than C++) in Perl and improved the performance by a factor of 60. To re-implement my algorithm in C to try to go even faster (theoretically possible of course) would however have meant an enormous investment in rewriting a C-PAN module and a lot of Perls guts in pure C to support the better algorithm that Perl had inspired.

    Update: this took place in ING Baring's market data department many years ago - the case was the calculation of correlation co-efficients, from N market prices, generating MxN(N-1)/2 values for M times at which prices where snapshot. The C-program did 2*M*N*N iterations through home-grown correlation coding. The Perl program used a CPAN module iterating it only N(N-1)/2 times with a few optimisations thrown in of the kind we've discussed already.

    One world, one people

      performance-aware algorithm design

      I fulle agree, however sometimes there is not a lot you can do. Or sometimes the cost is less important/irrelevant, only speed matters. To give an example, I'm working on over-constrained CSP's and the algorithms are al at least NPC. Speeds is very important. We will even settle for sub-optimal solutions if we can speed things up. This is exlactly the reason why I've been looking into genetic algorithms.

      If you can improve the performance of a C-program by a factor 60 by rewriting it in Perl I would argue it was a poor implementation in C in the first place. I'm a big fan of Perl but I'm not religious when it comes to programming, when I need speed there are normally better options available.

      Cheers

      Harry

        The problem wasn't that it was a bad implementation in C -- it just wasn't a system programming implementation in C with calls to system services everywhere. To take a very common example, a C system programmer will use system library calls to process a bunch of files by wildcard, whereas a C application programmer would probably use ksh for that part of the solution. A Perl programmer will also use system calls, but transparently :)

        One world, one people

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://876235]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-23 06:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found