这个简单的程序为什么运行结果是这样
#include <sys/times.h>
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
main(argc , argv)
int argc;
char* argv[];
{
int f1,f2,n;
long walltime;
clock_t c1,c2;
if(argc <=2)
{
printf( "You forgot to enter the file name! ");
exit(1);
}
f1=open(argv[1],0);
f2=creat(argv[2],0644);
printf( "buffersize user-time system-time wall-time\n ");
int buffersize=1;
int i;
for(i=0;i <15;i++)
{
char buf[buffersize];
struct tms timebuf;
c1=times(&timebuf);
while((n=read(f1,buf,buffersize))> 0)
write(f2,buf,n);
c2=times(&timebuf);
walltime = sysconf(_SC_CLK_TCK);
if(c2==-1)
{
printf( "Failed to accumulate the time! ");
exit(1);
}
printf( " %d %d %d %d\n ",buffersize,timebuf.tms_utime,timebuf.tms_stime,walltime);
close(f1);
close(f2);
buffersize=buffersize*2;
}
}
这个程序是想用不同的buffersize来计算拷贝时间
为什么每次结果都一样?
------解决方案--------------------还有啊,时间要相减才是拷贝用的时间。