Created
May 7, 2014 12:16
-
-
Save anonymous/b6f080d62654954f971b to your computer and use it in GitHub Desktop.
Measuring small consecutive memcpy
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<stdio.h> | |
#include<stdlib.h> | |
#include<string.h> | |
#include<time.h> | |
int main(){ | |
void *a, *b; | |
struct timespec start, end; | |
unsigned int i; | |
a = malloc(128); | |
b = malloc(128); | |
memset(a, 127, 128); | |
memset(b, 0, 128); | |
for(i=0;i<1000;i++){ | |
clock_gettime(CLOCK_MONOTONIC, &start); | |
memcpy(b, a, 32); | |
clock_gettime(CLOCK_MONOTONIC, &end); | |
{ | |
long int nsec = (end.tv_sec - start.tv_sec) * 1000000000 + | |
(end.tv_nsec - start.tv_nsec); | |
printf("%u ns\n", nsec); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment