For example, I want to create a square root table using array SQRT[i] to optimize a game, but I don't know if there is performance difference between the following initialization when accessing the value of SQRT[i]:
-
Hardcode array
int SQRT[]={0,1,1,1,2,2,2,2,2,3,3,.......255,255,255} -
Generate value at run time
int SQRT[65536]; int main(){ for(int i=0;i<65536;i++){ SQRT[i]=sqrt(i); } //other code return 0; }
Some example of accessing them:
if(SQRT[a*a+b*b]>something)
...
At start, I thought they should be the same, but I don't know if the program stores or access a hard-code array in different way. Also, I don't know if compiler will optimize the hard-code array to speed up the access time, is there performance difference between them when accessing the array?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire