读写测试代码

一、非DIO
1.tools.c
#include <time.h>
#include <sys/timeb.h>
#include "tools.h"

void wrtFile(char * filename, char * list, int count)
{
 int writefd = -1;
 int i;
 time_t writeltime1, writeltime2;
 struct timeb writetimebuffer1, writetimebuffer2;

 // before write, record time
 time (&writeltime1);
 ftime ( &writetimebuffer1 );

 if ( -1 != ( writefd = open( filename, O_WRONLY|O_CREAT) ) )
 {
  write( writefd, list, count );
  close(writefd);
    }
 else
 {
  printf( "error writting file!" );
 }

 // after writefile, record time
 time (&writeltime2);
 ftime ( &writetimebuffer2 );

 printf("write");
 showTimespanSpeed(writeltime1, writeltime2, writetimebuffer1.millitm, writetimebuffer2.millitm);
 //sleep(SLEEPTIME);
}

void rdFile(char * filename, char * list, int count)
{
 int readfd = -1;
 int i;
 time_t readltime1, readltime2;
 struct timeb readtimebuffer1, readtimebuffer2;

 // before read, record time
 time (&readltime1);
 ftime ( &readtimebuffer1 );

 if( -1 != ( readfd = open( filename, O_RDONLY) ) )
 {
  int readsize = read( readfd, list, count);
  printf("rdsize:%dM/n", readsize / 1000 / 1000);
  close(readfd);
    }
    else
    {
     printf( "Error opening file!/n");
 }

 // after readfile, record time
 time (&readltime2);
 ftime ( &readtimebuffer2 );

 printf("read");
 showTimespanSpeed(readltime1, readltime2, readtimebuffer1.millitm, readtimebuffer2.millitm);
 //sleep(SLEEPTIME);
}


void delFile ( int filenum )
{
 char name[50];
 time_t delltime1, delltime2;
 struct timeb deltimebuffer1, deltimebuffer2;

 // before del, record time
 time (&delltime1);
 ftime ( &deltimebuffer1 );

    int i;
    for ( i = 0; i < filenum; i++ )
    {
  char pathname[100] = "./filedir";
  sprintf( name, "%d", i);
  strcat( pathname, "/");
  strcat( pathname, name );
               
  unlink( pathname );

 }

 // after delfile, record time
 time (&delltime2);
 ftime ( &deltimebuffer2 );

 printf("del");
 showTimespanSpeed(delltime1, delltime2, deltimebuffer1.millitm, deltimebuffer2.millitm);
 //sleep(SLEEPTIME);
}

void showTimespanSpeed(int second1, int second2, int millisecond1, int millisecond2)
{
 printf("second1:%d,second2:%d,millisecond1:%d,millisecond2:%d/n", second1, second2, millisecond1, millisecond2 );
 int secondspan = second2 - second1;
 int millisecondspan = (1000 * secondspan) + millisecond2 - millisecond1;
 int speed = FILESIZEINBYTE / 1000 / millisecondspan;
 printf( "speed:%dM/s, millisecondspan:%dms/n", speed, millisecondspan );
}

void *thread1( ThreadInput *ti)
{
 char pathname[100] = "./wrtfiledir";       
 char name[50] = "file1";
 strcat( pathname, "/");       
 strcat( pathnam

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值