Skip to content

Instantly share code, notes, and snippets.

@medicalwei
Forked from anonymous/measure.c
Created May 7, 2014 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save medicalwei/6f04d0120bd37bc70bc0 to your computer and use it in GitHub Desktop.
Save medicalwei/6f04d0120bd37bc70bc0 to your computer and use it in GitHub Desktop.
#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