Created
May 13, 2011 05:10
-
-
Save electrum/970003 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
test: test.c Makefile | |
gcc -O3 -Wall -Werror -std=c99 -o test test.c |
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 <sys/time.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main() | |
{ | |
const int SIZE = 256 * 1024 * 1024; | |
int *x; | |
struct timeval ts, te, t; | |
x = malloc(SIZE * sizeof(int)); | |
gettimeofday(&ts, NULL); | |
for (int i = 0; i < SIZE; i++) { | |
x[i] = i; | |
} | |
gettimeofday(&te, NULL); | |
timersub(&te, &ts, &t); | |
printf("write = %d.%06d\n", (int) t.tv_sec, (int) t.tv_usec); | |
long m = 0; | |
for (int j = 0; j < 100000; j++) { | |
gettimeofday(&ts, NULL); | |
long n = 0; | |
for (int i = 0; i < SIZE; i++) { | |
n += x[i]; | |
} | |
gettimeofday(&te, NULL); | |
timersub(&te, &ts, &t); | |
float secs = (t.tv_sec + (t.tv_usec / 1000000.0)); | |
printf(" read = %d.%06d (%.1f MB/s)\n", | |
(int) t.tv_sec, (int) t.tv_usec, | |
((SIZE * sizeof(int)) / secs) / (1024 * 1024)); | |
m += n; | |
} | |
printf("%ld\n", m); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment