Skip to content

Instantly share code, notes, and snippets.

Created May 7, 2014 12:16
Show Gist options
  • Save anonymous/b6f080d62654954f971b to your computer and use it in GitHub Desktop.
Save anonymous/b6f080d62654954f971b to your computer and use it in GitHub Desktop.
Measuring small consecutive memcpy
#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