Skip to content

Instantly share code, notes, and snippets.

@wangzaixiang
Created September 17, 2012 13:44
Show Gist options
  • Save wangzaixiang/3737341 to your computer and use it in GitHub Desktop.
Save wangzaixiang/3737341 to your computer and use it in GitHub Desktop.
Call Write API 1M Count
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
main(){
struct timeval tv1, tv2;
gettimeofday(&tv1, NULL);
int fd = open("/dev/null", O_WRONLY);
char ch = 'H';
for(int i=0; i<8000000; i++){
write(fd, &ch, 1);
}
gettimeofday(&tv2, NULL);
printf("total time = %d\n", (tv2.tv_sec-tv1.tv_sec)*1000000+(tv2.tv_usec-tv1.tv_usec));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment