Last active
December 18, 2015 18:09
-
-
Save flgr/5823977 to your computer and use it in GitHub Desktop.
Simplistic way of measuring memcpy() performance on Unix systems.
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 <stdlib.h> | |
#include <string.h> | |
#include <stdio.h> | |
int main() { | |
struct timeval t0, t1; | |
unsigned int i; | |
unsigned int mb_size = 64; | |
unsigned int rep = 200; | |
for (unsigned int mb_size = 64; mb_size <= 1024; mb_size *= 2) { | |
size_t size = mb_size * 1024 * 1024; | |
void *src = malloc(size); | |
void *dst = malloc(size); | |
gettimeofday(&t0, NULL); | |
for (int i = 0; i < rep; i++) { | |
memcpy(src, dst, size); | |
} | |
gettimeofday(&t1, NULL); | |
free(src); | |
free(dst); | |
printf("Copied %d MB in %.2g seconds\n", mb_size, (t1.tv_sec - t0.tv_sec + 1E-6 * (t1.tv_usec - t0.tv_usec)) / rep); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment