Arithmetic Calculations Performance Question

Started by
5 comments, last by V-man 15 years, 4 months ago
Hey everyone! Is there a difference in performance when working on coordinates say from -1000 to 1000 in XYZ, and say from -50000 to 50000? Let's assume purely theoretically that I there are no precision problems when shrinking the coordinates, would it have better performance? I thought the answer to this question is 'no', because what does it matter if the polygon is 'large' or not? When the camera is at a relatively the same location, it looks the same size on the screen. Well, I'm not so sure anymore. Thanks in advance!
Advertisement
No one knows? :(
I can't think of anything that would cause a performance difference right now...

What made you think there's a difference?
No, there is no difference.
Quote:Original post by Rattenhirn
What made you think there's a difference?

Probably he thinks there's a difference, because it's more difficult for a human to calculate big numbers. :)

It's always the same for computers, because they calculate the numbers bit-by-bit.
A little example, 6 + 3 = 9 in binary form:
0110 (decimal 6)
+0011 (decimal 3)
-----
1001

The computer will do this in hardware. "Hardware" means certain chips on your processor which are capable of addition in this case. Note that such addition-chips can look very different and have very different benefits.
What the chip will do now is comparing each bit of both digits with each other, performing the boolean operations AND and XOR. Even if you have a 64 bit integer of which all bits are 0, the chip will still need to go through all of them and do these two boolean operations. And these operations won't go faster if the two bits are both 0 or anything like that :)
Hehe, no, didn't think so because it was more difficult for humans. :) Two friends of mine used some code a lecturer published (the lecturer used 'smaller' coordinates). One of them 'enlarged' the coordinates while the other used the same as the lecturer, and the smaller coordinates runs faster. Now, you might say, the one with slower app is an idiot and did something stupid, right? Well code seems very similar, and there is nothing that would slow one over the other.

I use 'large' coordinates, and figured I'd ask here before converting to 'smaller' ones.
I benchmarked it

for(i=0; i<16000000; i+=4)	{		array=<span class="cpp-number">200000</span>.<span class="cpp-number">0</span>;<br>		array[i+<span class="cpp-number">1</span>]=<span class="cpp-number">300000</span>.<span class="cpp-number">0</span>;<br>		array[i+<span class="cpp-number">2</span>]=<span class="cpp-number">500000</span>.<span class="cpp-number">0</span>;<br>		array[i+<span class="cpp-number">3</span>]=<span class="cpp-number">800000</span>.<span class="cpp-number">0</span>;<br>	}<br><br>Begintimer();<br><span class="cpp-keyword">for</span>(i=<span class="cpp-number">0</span>; i&lt;<span class="cpp-number">16000000</span>; i+=<span class="cpp-number">4</span>)<br>	{<br>		array*=array;<br>		array[i+<span class="cpp-number">1</span>]*=array[i+<span class="cpp-number">1</span>];<br>		array[i+<span class="cpp-number">2</span>]*=array[i+<span class="cpp-number">2</span>];<br>		array[i+<span class="cpp-number">3</span>]*=array[i+<span class="cpp-number">3</span>];<br>	}<br>Endtimer();<br><br></pre></div><!–ENDSCRIPT–><br><!–STARTSCRIPT–><!–source lang="cpp"–><div class="source"><pre><br><span class="cpp-keyword">for</span>(i=<span class="cpp-number">0</span>; i&lt;<span class="cpp-number">16000000</span>; i+=<span class="cpp-number">4</span>)<br>	{<br>		array=<span class="cpp-number">2</span>.<span class="cpp-number">0</span>;<br>		array[i+<span class="cpp-number">1</span>]=<span class="cpp-number">3</span>.<span class="cpp-number">0</span>;<br>		array[i+<span class="cpp-number">2</span>]=<span class="cpp-number">5</span>.<span class="cpp-number">0</span>;<br>		array[i+<span class="cpp-number">3</span>]=<span class="cpp-number">0</span>.<span class="cpp-number">0</span>;<br>	}<br><br>Begintimer();<br><span class="cpp-keyword">for</span>(i=<span class="cpp-number">0</span>; i&lt;<span class="cpp-number">16000000</span>; i+=<span class="cpp-number">4</span>)<br>	{<br>		array*=array;<br>		array[i+<span class="cpp-number">1</span>]*=array[i+<span class="cpp-number">1</span>];<br>		array[i+<span class="cpp-number">2</span>]*=array[i+<span class="cpp-number">2</span>];<br>		array[i+<span class="cpp-number">3</span>]*=array[i+<span class="cpp-number">3</span>];<br>	}<br>Endtimer();<br><br><br></pre></div><!–ENDSCRIPT–><br><br>It took about 44 sec &#111;n a Core2 in both cases
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement