Created
November 18, 2014 01:49
-
-
Save c0ldlimit/793f38e6c9e477f9f0b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <time.h> | |
// my CPU has 32K of L1 cache | |
#define L1_CACHE_CAPACITY (32768 / sizeof(int)) | |
int array[L1_CACHE_CAPACITY][L1_CACHE_CAPACITY]; | |
struct timespec time_diff(struct timespec start, struct timespec end) { | |
struct timespec temp; | |
if (end.tv_nsec - start.tv_nsec < 0) { | |
temp.tv_sec = end.tv_sec - start.tv_sec - 1; | |
temp.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec; | |
} else { | |
temp.tv_sec = end.tv_sec - start.tv_sec; | |
temp.tv_nsec = end.tv_nsec - start.tv_nsec; | |
} | |
return temp; | |
} | |
int main(void) { | |
struct timespec start, end; | |
int i, j; | |
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); | |
for (i=0; i<L1_CACHE_CAPACITY; i++) | |
for (j=0; j<L1_CACHE_CAPACITY; j++) | |
array[i][j] = i*j; | |
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); | |
struct timespec delta = time_diff(start, end); | |
printf("Delta is %ld:%6ld\n", delta.tv_sec, delta.tv_nsec); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment