Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <time.h>
- #include <stdio.h>
- #include <stdlib.h>
- int SIZE = 1024 * 1024 * 1024;
- int CLSIZE = 64;
- void test(char *a, int step) {
- clock_t start = clock();
- for (int i = 0; i < SIZE; i += step) {
- a[i] *= 2;
- }
- clock_t end = clock();
- float ms = (float)(end - start) / (CLOCKS_PER_SEC / 1000);
- printf("Step = %d: %f ms\n", step, ms);
- }
- void main() {
- char *aaa = (char *)malloc(SIZE);
- test(aaa, 4);
- test(aaa, 64);
- }
- // $ gcc cache_line.c -std=c99 -O0 -o cache_line && ./cache_line
- // Step = 4: 813.681030 ms
- // Step = 64: 110.019997 ms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement