-Using this as a base for comparison:
float x = 0;
float y = 0;
float xx = 1;
float yy = 2;
for(int i=0;i<100000;++i)
{
x = xx; //simple assignment test.. this is actually pretty fast for built in value types!
y = yy;
xx = x;
yy = y;
}
3x slower
Vector2 a;
Vector2 b;
for(int i=0;i<100000;++i)
{
a.x = b.x;
b.x = a.x;
a.y = b.y;
b.y = a.y;
}
This is still very fast. Only 2.1 times slower than the base test:
Vector2 a;
Vector2 b;
for(int i=0;i<100000;++i)
{
a = b; //evaluates to a function call.
b = a;
}
8x slower ???
class test
{
Vector2 a;
Vector2 b;
void run()
{
for(int i=0;i<100000;++i)
{
a = b; // a, b are now class members, same speed as if declared global
b = a;
}
}
}
also 8x slower
class V
{
Vector2 v;
}
V a;
V b;
for(int i=0;i<100000;++i)
{
a.v = b.v;
b.v = a.v;
}
Tested these in release using windows performance timers.
Is this expected in terms of speed? -Also wondering if there's any tricks to get class members to be better 'cached' when executing a function within that class? (I use a lot of classes)
Thanks.