#include #include #include double now() { struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_sec + (tv.tv_usec / 1e6); } #define NITER 100000000 #define XSIZE 4096 int main() { char *data; int *d; unsigned i, a; double t1, t2; data = malloc(2*XSIZE); printf("aligned data is at %p\n", data); d = (int*)data; t1 = now(); for (i = 0; i < NITER; i++) { (*d)++; d++; if (i % 1024 == 0) d = (int*)data; } t2 = now(); printf("aligned: %0.1f ops/s\n", NITER / (t2-t1)); data++; d = (int*)data; t1 = now(); for (i = 0; i < NITER; i++) { (*d)++; d++; if (i % 1024 == 0) d = (int*)data; } t2 = now(); printf("unaligned: %0.1f ops/s\n", NITER / (t2-t1)); }