Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Perl slower than java

by ikegami (Patriarch)
on Dec 08, 2010 at 22:57 UTC ( [id://876134]=note: print w/replies, xml ) Need Help??


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

That Perl smells like LISP ;)

Replies are listed 'Best First'.
Re^3: Perl slower than java
by Anonymous Monk on Dec 08, 2010 at 23:03 UTC
    Well, I've never used Lisp, but I did stay at a Holiday Inn last night read Higher-Order Perl, so I'll take that as a compliment.
Re^3: Perl slower than java
by Christian888 (Acolyte) on Dec 08, 2010 at 23:05 UTC
    My perl smells like a beginner’s fear of writing a code that he will not be able to read again in six months time :-) Hence I did everything as explicitly as possible, including all parentheses. I was not aware that being explicit would slow the code in perl. Is this correct? BTW, the slowest sub seems to be “get_phenotype” I think it take up to 25 milliseconds on my machine, which is a lot compared to the rest of the code. Can you see anything that might be causing the slowdown in that sub?

      I saw no real issues with your code.

      Style-wise, @$chromosome1[$i] is needless use of an array slice, $$chromosome1[$i] and $chromosome1->[$i] are more appropriate. (The latter is usually considered more readable, but they are equivalent.)

      Also, for my $i ( 0 .. ( $population_size - 1 ) ) { ...; $new_population[$i] = ...; } could be simplified to for ( 1 .. $population_size ) ) { ...; push @new_population, ...; }

      Performance-wise, there's some array copying that could probably be avoid. Some can definitely be avoided by returning an array instead of a reference to an array. I don't know if it'll amount to much time.

      Also, you're recompiling /\d/ and /\D/ repeatedly. Perhaps you should use qr/\d/ and qr/\D/ instead of '\d' and '\D'. This won't amount to much, I suspect.

      There's surely tricks you can use to speed up your code, but that's not to say you did anything wrong.

      Perl is typeless. That will make it slower in general. You might want to take a peak at PDL for this project.

      The odd extra bracket isn't the point - it's the maximal iterations in your algorithm that is the issue. Although the suggestion about using one liners inline does save a fair amount. But a really well-conceived algorithm ought to reduce iterations by several orders of magnitude. labelled loops with winning exits might be a start. Also, sorting data once to reduce iterating through is better than always iterating the lot. Even with rand, you could generate blocks of data in advance and sort them, rather than pick up values on the fly.

      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://876134]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-03-29 13:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found