Performance of combining local integers
Posted: Sun Jul 23, 2006 9:07 am
I performed some tests on the speed of combining more than one number in a local int vs. putting them all in their own seperat ints. Results varied, but I think a performance increase of at least 22% is likely with 4 8-bit numbers, increasing as the number of locals stored on one object does. The code executes faster even without counting the increased speed of a GetLocalInt() call when the number of local variables are reduced.
The 22% gain was seen comparing 10 GetLocalInt() calls on an object with 10 local integers to 4 GetLocalInt() calls, 10 GetPiecewiseInteger() calls on an object with 4 local integers. 22% was the gain over 100,000 iterations.
Normal code:
Piecewise code:
To get these piecewise numbers, I use this function in acr_tools_i:
So this is something which could be usefull when memory use is important, or we are storing a lot of locals on one object, or both.
The 22% gain was seen comparing 10 GetLocalInt() calls on an object with 10 local integers to 4 GetLocalInt() calls, 10 GetPiecewiseInteger() calls on an object with 4 local integers. 22% was the gain over 100,000 iterations.
Normal code:
Code: Select all
GetLocalInt(OBJECT_SELF, "V0");
GetLocalInt(OBJECT_SELF, "V1");
GetLocalInt(OBJECT_SELF, "V2");
GetLocalInt(OBJECT_SELF, "V3");
GetLocalInt(OBJECT_SELF, "V4");
GetLocalInt(OBJECT_SELF, "V5");
GetLocalInt(OBJECT_SELF, "V6");
GetLocalInt(OBJECT_SELF, "V7");
GetLocalInt(OBJECT_SELF, "V8");
GetLocalInt(OBJECT_SELF, "V9");
...Code: Select all
v0 = GetLocalInt(OBJECT_SELF, "V0");
v1 = GetLocalInt(OBJECT_SELF, "V1");
v2 = GetLocalInt(OBJECT_SELF, "V2");
GetPiecewiseInteger(v0, 0, 7);
GetPiecewiseInteger(v0, 8, 15);
GetPiecewiseInteger(v0, 16, 23);
GetPiecewiseInteger(v0, 24, 31);
GetPiecewiseInteger(v1, 0, 7);
GetPiecewiseInteger(v1, 8, 15);
GetPiecewiseInteger(v1, 16, 23);
GetPiecewiseInteger(v1, 24, 31);
GetPiecewiseInteger(v2, 0, 7);
GetPiecewiseInteger(v2, 8, 15);
...Code: Select all
int GetPiecewiseInteger(int nNum, int nStartBit, int nEndBit) {
nNum = nNum << nEndBit;
return ( nNum >>> (nStartBit + nEndBit) );
}