Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2004:
[Freeciv-Dev] Re: (PR#9755) provide distribute() in the utility code

[Freeciv-Dev] Re: (PR#9755) provide distribute() in the utility code

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#9755) provide distribute() in the utility code
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 21 Aug 2004 08:48:16 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: >

Per I. Mathisen wrote:
> <URL: >
> On Fri, 20 Aug 2004, Jason Short wrote:
>>This patch provides a function distribute() in the utility code:
>> void distribute(int number, int groups, int *ratios, int *result);
>>This will distribute "number" elements into "groups" groups with ratios
>>given by the elements in "ratios".The resulting division is put into
>>the "result" array.
>>The only user (so far) is the trade disribution code.
> Check speed. This code is run very often. Consider doing away with your
> asserts and possibly making it inline.

In a single autogame:

Old code:

real    1m20.911s
user    1m12.334s
sys     0m0.489s

New code:

real    1m18.001s
user    1m12.145s
sys     0m0.332s

I'm not sure I believe the new algorithm is faster.  But I don't see any 
reason why it would be slower.


And another one:

Old code:

real    1m38.259s
user    1m24.959s
sys     0m0.770s

New code:

real    1m32.612s
user    1m24.200s
sys     0m0.437s

So maybe it is faster.  But I have no idea why.  (Savegames were 
unchanged by the patch in both these autogames.)


Oh wait, I know why.  It's because the original code had a very 
inefficient loop.  It checked every condition in each loop, even though 
finding one condition usually meant the loop had to be restarted or was 


[Prev in Thread] Current Thread [Next in Thread]