[ODE] dRandInt & performance

Yordan Gyurchev yg at gyurchev.com
Mon May 2 21:03:17 MST 2005


Hi,

This concerns platforms that have little or no support for "double"s. (PS2 
in particular)

In the quickstep inner loop of the solver when RANDOMLY_REORDER_CONSTRAINTS 
is defined (and it is defined by default) it uses dRandInt. Although I use 
"single" build the dRandInt uses double under the bonnet and is unnecessary 
heavy for that tight loop.

On my PS2 build replacing dRandInt with a simple inline custom randomInt 
function (see later) improved for me performance of the solver over 200%.

I'm not sure what the performance gain is (if any) on an Intel type of 
platform I haven't profiled that. I would guess that if not for the double 
the an inline func will reduce the overhead of calling library rand() 
function at least.

Hope this helps someone,
Yordan Gyurchev

PS: a simple multiply truncate random int function implementation to try:

extern unsigned int nSeed;

//return values from 0 to scale-1
inline unsigned int RandomInt(unsigned int scale)
{
 nSeed=(nSeed*16807) & 0x7fffffff;

 return ((nSeed>>15)*scale)>>16;
} 




More information about the ODE mailing list