Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^4: Perl slower than java

by ikegami (Patriarch)
on Dec 09, 2010 at 04:55 UTC ( [id://876165]=note: print w/replies, xml ) Need Help??


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

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.

Log In?
Username:
Password:

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

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

    No recent polls found