Created
January 9, 2009 19:14
-
-
Save kig/45222 to your computer and use it in GitHub Desktop.
small memory access benchmark
This file contains hidden or 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 <stdio.h> | |
#include <stdlib.h> | |
#define TEST_SIZE 10000000 | |
long arr[TEST_SIZE]; | |
void usage (char *name) | |
{ | |
printf("USAGE: %s [forward|reverse|both]", name); | |
exit (1); | |
} | |
int main (int argc, char *argv[]) | |
{ | |
int i,j; | |
char mode; | |
if (argc != 2) | |
usage (argv[0]); | |
mode = argv[1][0]; | |
if (mode != 'f' && mode != 'r' && mode != 'b') | |
usage (argv[0]); | |
for (j=0; j<100; j++) { | |
switch (mode) { | |
case 'f': | |
for (i=1; i<TEST_SIZE; i++) | |
arr[i-1] += arr[i]; | |
break; | |
case 'r': | |
for (i=TEST_SIZE-1; i>=1; i--) | |
arr[i-1] += arr[i]; | |
break; | |
case 'b': | |
for (i=TEST_SIZE-1; i>=1; i--) | |
arr[TEST_SIZE-i] += arr[i]; | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment