Created
May 21, 2013 14:16
-
-
Save nodakai/5620116 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
#define _POSIX_C_SOURCE 199309L | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <time.h> | |
int main(int argc, char *argv[]) { | |
int megs = 100; | |
size_t buflen; | |
void *buf; | |
struct timespec ts0, ts1; | |
double diffNsec, gbps; | |
if (1 < argc) | |
megs = atoi(argv[1]); | |
buflen = (size_t)megs * 1024 * 1024; | |
if (NULL == (buf = malloc(buflen))) { | |
printf("malloc failed\n"); | |
exit(10); | |
} | |
clock_gettime(CLOCK_REALTIME, &ts0); /* warming up */ | |
memset(buf, 0x11, buflen); /* warming up */ | |
clock_gettime(CLOCK_REALTIME, &ts0); | |
memset(buf, 0x11, buflen); | |
clock_gettime(CLOCK_REALTIME, &ts1); | |
diffNsec = (ts1.tv_nsec - ts0.tv_nsec) + 1e9 * (ts1.tv_sec - ts0.tv_sec); | |
gbps = buflen / diffNsec; | |
printf("%f sec; %f GB/s\n", diffNsec * 1e-9, gbps); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment