|
![](/i/fill.gif) |
Larry Hudson wrote:
>> I just ran a quick test that shows that this algorithm is actually
>> 3 to 4 times *slower* than Kiss64. See attached source file. Test was
>> run like this:
>>
>> > gcc -O3 -lm -o random random.c
>>
>> > ./random
>> Empty loop: 0ms
>> Kiss64 (int): 6622ms
>> Kiss64 (dbl): 5003ms
>> Alvo: 21021ms
>>
> Interesting... I played with your test example on my system and got
> rather different results. My system is much older and slower -- 32-bit
> Athlon 2000+, old version of Linux & gcc. (I won't bother going into
> the reasons why I still use Fedora 3, I do have and use newer versions
> of Linux. But this is what I still use to read these newsgroups.)
>
> Anyway, I had to reduce your loop count by a factor of 10 to get timing
s
> similar to yours, but I found the Alvo was _faster_ than the Kiss64.
>
> Then I made a couple changes, first, instead of the call to floor() I
> used a simple type cast to int. Second, since the original performs th
e
> same multiplication twice, I changed it to use a temporary variable
> instead.
>
Funny, I did try it with a temp variable instead of two mults. It
didn't change the timings so I assumed that my version of gcc was
able to optimize it and kept the one closest to the algorithm.
I hadn't tried with a cast instead of "floor" and it is indeed
faster, though still not as fast as Kiss64.
As for the reason why Kiss64 is faster on my computer, I suppose
it's due to the fact that it is 64 bits and therefore able to do
some operations in one instruction while 32 bit computers need
several instructions to do the same thing.
> The original relevant line:
> alvo_x = (alvo_s * alvo_x) - floor (alvo_s * alvo_x);
>
> My first change:
> alvo_x = (alvo_s * alvo_x) - (int)(alvo_s * alvo_x);
>
> My second change: (Also adding "double alvo;" to the variable list)
> alvo = alvo_s * alvo_x;
> alvo_x = alvo - (int)alvo;
>
> Here are the timings on my last run:
> 100000000 loops:
> Empty loop: 255ms
> Kiss64 (int): 4568ms
> Kiss64 (dbl): 8980ms
> Alvo: 3626ms
> Alvo: 2646ms: (int with 2 mults)
> Alvo: 325ms: (int with 1 mult)
>
Interesting that on your computer the dbl version of Kiss64 should
be so much slower than the int version while on mine the results are
comparable.
By simple curiosity, I've also added Warp's implementation of Isaac
and here is the result (see attached code):
> g++ -O3 -lm -o random random.cc IsaacRand.cc
> ./random
Empty loop: 0ms
Kiss64 (int): 6623ms
Kiss64 (dbl): 5003ms
Alvo (floor): 21539ms
Alvo (cast): 14608ms
Alvo (tmp+cast): 14664ms
Isaac: 10540ms
Jerome
--
mailto:jeb### [at] free fr
http://jeberger.free.fr
Jabber: jeb### [at] jabber fr
Post a reply to this message
Attachments:
Download 'us-ascii' (2 KB)
|
![](/i/fill.gif) |