#include <stdio.h>
#include <time.h>
#include <string.h>
int main(void) {
unsigned int a1 = 0xf3040506;
unsigned int *a = ( unsigned int *)&a1;
unsigned char *m = (unsigned char* )&a1;
unsigned long forcount = 5000000000 ,i;
unsigned char r , g , b , al;
printf("r p %x\n", (unsigned char) *a
); printf("g p %x\n", (unsigned char) (*a
>> 8)); printf("b p %x\n", (unsigned char) (*a
>> 16) ); printf("a p %x\n", (unsigned char) (*a
>> 24) );
clock_t t;
for(i = 0;i < forcount ;i++)
{
r = m[0];
g = m[1];
b = m[2];
al = m[3];
}
printf ("pointer take (%f seconds).\n",((float)t
)/CLOCKS_PER_SEC
);
for(i = 0;i < forcount ;i++)
{
r = (unsigned char) *a;
g = (unsigned char) (*a >> 8);
b = (unsigned char) (*a >> 16);
al = (unsigned char) (*a >> 24);
}
printf ("shift take (%f seconds).\n",((float)t
)/CLOCKS_PER_SEC
);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDx0aW1lLmg+IAojaW5jbHVkZSA8c3RyaW5nLmg+CgppbnQgbWFpbih2b2lkKSB7IAogICAgdW5zaWduZWQgaW50IGExID0gMHhmMzA0MDUwNjsKICAgIHVuc2lnbmVkIGludCAqYSA9ICggdW5zaWduZWQgaW50ICopJmExOwogICAgdW5zaWduZWQgY2hhciAqbSAgPSAodW5zaWduZWQgY2hhciogKSZhMTsKICAgIHVuc2lnbmVkIGxvbmcgZm9yY291bnQgPSA1MDAwMDAwMDAwICAsaTsKICAgIHVuc2lnbmVkIGNoYXIgciAsIGcgLCBiICwgYWw7CiAgICAKICAgIAoJcHJpbnRmKCIleFxuIiwgKmEpOwoKCQoJcHJpbnRmKCJyIGkgJXhcbiIsIG1bMF0pOwoJcHJpbnRmKCJnIGkgJXhcbiIsIG1bMV0pOwoJcHJpbnRmKCJiIGkgJXhcbiIsIG1bMl0pOwoJcHJpbnRmKCJhIGkgJXhcbiIsIG1bM10pOwoJCgkKCQoJcHJpbnRmKCJyIHAgJXhcb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