#include #include #include #include #include #include #include #include #define MX_BLOCK 8192 #define MN_BLOCK 16 #define FILE_SIZE 1024*2048 #define MX_OUTPUT 32 int main(int argc, char** argv) { struct tms ticks; char buffer[MX_BLOCK]; char c = 'a'; int block_size=MN_BLOCK, nosync[MX_OUTPUT],sync[MX_OUTPUT]; int v, i, file, num_writes, start, test; FILE *data; for ( i = 0; i < MX_BLOCK; i++ ) buffer[i] = c; file = open("tester.dat", O_WRONLY | O_CREAT | O_SYNC ,S_IRWXU); test=1; printf("number of clock ticks per second=%ld", sysconf(_SC_CLK_TCK)); while (block_size < MX_BLOCK){ lseek(file,0,SEEK_SET); block_size *= 2; num_writes=FILE_SIZE/block_size; start=times(&ticks); for ( i = 0; i < num_writes; i++ ) write(file, buffer, block_size); sync[test]=times(&ticks)-start; fprintf(stderr,"block size=%d, ticks=%d\n",block_size,sync[test]); test++; } close(file); file = open("tester.dat", O_WRONLY | O_CREAT,S_IRWXU); test=1; block_size=MN_BLOCK; while (block_size < MX_BLOCK){ lseek(file,0,SEEK_SET); block_size *= 2; num_writes=FILE_SIZE/block_size; start=times(&ticks); for ( i = 0; i < num_writes; i++ ) write(file, buffer, block_size); nosync[test]=times(&ticks)-start; fprintf(stderr,"block size=%d, ticks=%d\n",block_size,nosync[test]); test++; } close(file); data=fopen("plot_data","w"); test=1; block_size=MN_BLOCK; while (block_size < MX_BLOCK){ block_size *= 2; fprintf(data,"%d %d %d\n",block_size,sync[test],nosync[test]); test++; } return 0; }