Skip to content

Instantly share code, notes, and snippets.

@richcole
Created September 28, 2012 02:52
Show Gist options
  • Save richcole/3797683 to your computer and use it in GitHub Desktop.
Save richcole/3797683 to your computer and use it in GitHub Desktop.
How fast is my desktop - 1.2GB/s
/*
* Note this just tests a single core:
*
* My work desktop: 1.2GB/s
* My home desktop: 1.4GB/s
* My raspberry pi: 200 MB/s
*/
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
double diff(struct timeval *after, struct timeval *before) {
double result = 0;
result += after->tv_sec - before->tv_sec;
result += (after->tv_usec - after->tv_usec) / 1000000.0;
return result;
}
int main(int argc, char **argv) {
struct timeval before, after;
int len1 = 1024 * 1024 * 100;
int len2 = 100;
int *buf = malloc(len1 * sizeof(int));
int sum = 0;
int i = 0;
int j = 0;
gettimeofday(&before, 0);
for(j=0;j<len2;j++) {
for(i=0;i<len1;++i) {
sum += buf[i];
}
}
gettimeofday(&after, 0);
fprintf(stdout, "%lf MB/s\n", (len1 * len2 * sizeof(int)) / (1024.0 * 1024.0) / diff(&after, &before));
return sum;
}
@richcole
Copy link
Author

gcc -O -o test test.c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment