Skip to content

Instantly share code, notes, and snippets.

@liyanage
Created November 25, 2009 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liyanage/243001 to your computer and use it in GitHub Desktop.
Save liyanage/243001 to your computer and use it in GitHub Desktop.
// CFLAGS='-std=c99 -arch x86_64' make cachetest && ./cachetest
#include <stdio.h>
#include <time.h>
void a();
void b();
int main() {
time_t s;
s = time(NULL);
for (int i = 0; i < 100000; i++) a();
printf("a %ld\n", time(NULL) - s);
s = time(NULL);
for (int i = 0; i < 100000; i++) b();
printf("b %ld\n", time(NULL) - s);
}
void a() {
unsigned long array[256][256];
for (int i = 0; i < 256; i++) {
for (int j = 0; j < 256; j++) {
array[i][j] = i * j;
}
}
}
void b() {
unsigned long array[256][256];
for (int i = 0; i < 256; i++) {
for (int j = 0; j < 256; j++) {
array[j][i] = i * j;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment