Zynq_Mp----测试SSD读写文件的速度

    在使用SSD时,首先由Linux系统识别/dev/sda设备文件节点,以下是测试步骤。

  • 挂载/dev/sda 

     ① mkfs.vfat -F 32 /dev/sda

     ② mount  /dev/sda  /mnt

     ③ cd  /mnt                                进入mnt目录,相当于进入SSD目录

  • 测试时间

      int gettimeofday(struct timeval tv,struct timezone *tz) 这个函数用于获取从今日凌晨到现在的时间差,常用于事件的耗时。

      struct timeval { int tv_sec;int  tv_usec;}

      linux测试时间差的程序如下:

 

     double GetTime(void)
      {
          struct timeval t;
          gettimeofday(&t, NULL);
          return (t.tv_sec + 1E-6 * t.tv_usec);
      }
  • 读写速度的程序

#include
#include
#include

#define DATA_SIZE         1024*1024*1024
#define M_DATA_SIZE     1024*1024

double GetTime(void)
{
    struct timeval t;
    gettimeofday(&t, NULL);
    return (t.tv_sec + 1E-6 * t.tv_usec);
}


int main()
{
    unsigned int i;
    unsigned int SSDReadRate = 0;
    unsigned int SSDWriteRate = 0;

    double  TimeReadStart = 0.00;
    double  TimeReadTotal = 0.00;
    double  TimeWriteStart = 0.00;
    double  TimeWriteTotal = 0.00;

    unsigned char SSDReadData[1024] = {0};
    unsigned char SSDWriteData[1024] = {0};
    FILE *pWrite_FILE = NULL;
    FILE *pRead_FILE = NULL;

    for(i=0; i<1024; i++)
    {
        SSDWriteData[i] = i % (0xFF);
    }

    //Write Process
    TimeWriteStart = GetTime();
    pWrite_FILE = fopen("SSD_Write.bin", "wb+");
    for(i=0; i<(DATA_SIZE/1024); i++)
    {
        fwrite(SSDWriteData, sizeof(unsigned char), 1024, pWrite_FILE);
    }
    fclose(pWrite_FILE);
    pWrite_FILE = NULL;
    TimeWriteTotal = GetTime() - TimeWriteStart;
    printf("Write SSD 1G data in %.3f secs \n", TimeWriteTotal);
    SSDWriteRate = (unsigned int)(1024 / TimeWriteTotal);
    printf("The Rate of SSD Write data is %dM/sec.\n", SSDWriteRate);

    //Read Process
    TimeReadStart = GetTime();
    pRead_FILE = fopen("SSD_Write.bin", "rb" );
    if(pRead_FILE == NULL)
    {
        printf("Open file failure.\n");
    }


    for(i=0; i<(DATA_SIZE/1024); i++)
    {
        fread(SSDReadData, sizeof(unsigned char), 1024, pRead_FILE);
    }
    fclose(pRead_FILE);
    pRead_FILE = NULL;
    TimeReadTotal = GetTime() - TimeReadStart;
    printf("Read SSD 1G data in %.3f secs \n", TimeReadTotal);
    SSDReadRate = (unsigned int)(1024 / TimeReadTotal);
    printf("The Rate of SSD Read data is %dM/sec.\n", SSDReadRate);

    return 0;
}

 

你可能感兴趣的:(Xilinx)