#include
#include
#include
#include
#include
void mem_seq_read(char* ptr,int len,int loop);
void mem_seq_write(char* ptr,int len,int loop);
int read_test(int len);
int write_test(int len);
int test_size[]={
256,
512,
1024,
1024*2,
1024*4,
1024*8,
1024*16,
1024*32,
1024*64,
1024*128,
1024*256,
1024*512,
1024*1024,
1024*1024*2,
1024*1024*4,
1024*1024*8,
1024*1024*16,
1024*1024*32,
1024*1024*64
};
int main(int argc,char* argv[])
{
int i;
while(1)
{
printf("read test : \n");
for(i=0;i
read_test(test_size[i]);
}
printf("write test : \n");
for(i=0;i
write_test(test_size[i]);
}
}
return 0;
}
int read_test(int len)
{
char *buf,*test_buf;
int loop;
int count=0;
int diff;
double speed;
struct timeval start_time,end_time;
buf=(char*)malloc(len+32);
if(!buf){
printf("allocate buf(%d) failed\n",len);
return -1;
}
test_buf=(char*)(((unsigned long)buf&(0xffffffe0))+32);
loop=64*1024*1024/len;
gettimeofday(&start_time,NULL);
while(1){
mem_seq_read(test_buf,len,loop);
count++;
gettimeofday(&end_time,NULL);
if(end_time.tv_sec-start_time.tv_sec>=5){
break;
}
}
diff=(end_time.tv_sec-start_time.tv_sec)*1000000+(end_time.tv_usec-start_time.tv_usec);
speed=1.0*count*len/diff*loop;
//speed=(len*loop*count)*1.0/diff;
printf("test size is %d ,count is %d , speed is %f MBps\n",len,count,speed);
free(buf);
return 0;
}
int write_test(int len)
{
char *buf,*test_buf;
int loop;
int count=0;
int diff;
double speed;
struct timeval start_time,end_time;
buf=(char*)malloc(len+32);
if(!buf){
printf("allocate buf(%d) failed\n",len);
return -1;
}
test_buf=(char*)(((unsigned long)buf&(0xffffffe0))+32);
loop=64*1024*1024/len;
gettimeofday(&start_time,NULL);
while(1){
mem_seq_write(test_buf,len,loop);
count++;
gettimeofday(&end_time,NULL);
if(end_time.tv_sec-start_time.tv_sec>=5){
break;
}
}
diff=(end_time.tv_sec-start_time.tv_sec)*1000000+(end_time.tv_usec-start_time.tv_usec);
speed=1.0*count*len/diff*loop;
//speed=(len*loop*count)*1.0/diff;
printf("test size is %d ,count is %d , speed is %f MBps\n",len,count,speed);
free(buf);
return 0;
}
阅读(1014) | 评论(0) | 转发(0) |