in reply to Re: Perl slower than java
in thread Perl slower than java

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

Replies are listed 'Best First'.
Re^3: Perl slower than java
by dHarry (Abbot) on Dec 09, 2010 at 12:43 UTC

    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