[Melbourne-pm] Timer::HiRes and alarms? (Was: AI Contest)

Kim Hawtin kim at hawtin.net.au
Wed Nov 10 20:56:09 PST 2010


Toby Corkindale wrote:
> Did you ever establish what was going on here?
> 
> Also, I was just wondering - have you actually been having trouble doing 
> enough processing inside 1000 ms?
> 
> There was a point when I was exceeding it, but I was doing a lot of work 
> over and over; It was helpful to create some data structures to hold 
> everything at the start of each that I could just reference later.
> Also, note that some data won't change at all over the course of the 
> game - the location, growth rates, and distances between planets.
> 
> I note that the default starter packages are not terribly optimised 
> either. For instance, whenever you request a planet by ID, it finds it 
> by iterating over the whole lot of planets, and checking to see if the 
> ID matches. >.<
> A quick optimisation would be to use List::Util's "first", and a better 
> optimisation would be to store the planets in a damn hash table.
> (List::Util is in core Perl 5.8.8 isn't it?)
> 
> I recommend sticking the fleets into a hash table based on destination 
> while you're at it..

I was getting restless about frequently timing out. Used NYTProfile. Did 
away with all the hashes and implemented them in arrays. Used constants 
for indexes instead of hash keys. Went from 980ms to typically 270ms per 
turn. Now it only times out when theres more than 100 or so of my fleets 
on the move and that seems to be the parsing code ...

regards,

Kim


More information about the Melbourne-pm mailing list