SSD Electronic disk speed detection under Linux

Source: Internet
Author: User

Code:

#include <stdio.h> #include <sys/time.h> #include <fcntl.h> #include <pthread.h> unsigned char    pbuffer[1024*1024*8];//Shared buffer void testssd1 (int *ch)//write test {int i=0;        int FD; if (*ch==0) fd = open ("/ssd1/test.dat", o_rdwr| O_creat); if (*ch==1) fd = open ("/ssd2/test.dat", o_rdwr| O_creat); if (*ch==2) fd = open ("/ssd3/test.dat", o_rdwr| O_creat); if (*ch==3) fd = open ("/ssd4/test.dat", o_rdwr| O_creat); if (*ch==4) fd = open ("/ssd5/test.dat", o_rdwr| O_creat); if (*ch==5) fd = open ("/ssd6/test.dat", o_rdwr| O_creat); if (*ch==6) fd = open ("/ssd7/test.dat", o_rdwr| O_creat); if (*ch==7) fd = open ("/ssd8/test.dat", o_rdwr|    O_creat);        if (fd<0) {printf ("%d open error!\n", *ch);    return;    } for (i=0;i<32;i++) write (fd,pbuffer,1024*1024*8);//per 8M, total 256MB close (FD);    printf ("ssd%d test over!\n", *ch); return;} void testssd2 (int *ch)//Read Test {    int i=0;    int fd;         if (*ch==0)                fd = open ("/ssd1/ Test.dat ", o_rdwr| O_creat);    if (*ch==1)         fd = open ("/ssd2/test.dat", o_rdwr| O_creat);    if (*ch==2)         fd = open ("/ssd3/test.dat", o_rdwr| O_creat);    if (*ch==3)         fd = open ("/ssd4/test.dat", o_rdwr| O_creat);    if (*ch==4)         fd = open ("/ssd5/test.dat", o_rdwr| O_creat);    if (*ch==5)         fd = open ("/ssd6/test.dat", o_rdwr| O_creat);    if (*ch==6)         fd = open ("/ssd7/test.dat", o_rdwr| O_creat);    if (*ch==7)         fd = open ("/ssd8/test.dat", o_rdwr| O_creat);    if (fd<0)     {      &nbsP printf ("%d open error!\n", *ch);        return;   }     for (i=0;i<32;i++)         read (fd,pbuffer,1024*1024*8);     Close (FD);    printf ("ssd%d test over!\n", *ch);    return;}    int main () {printf ("This is the SSD speed Test begin!\n\n");      pthread_t _id[8];    int ret,i,ch[8];    struct Timeval start;        struct Timeval end;    float speed;    for (i=0;i<1024*1024*8;i++)//Initialize buffer pbuffer[i] = i&0xff; Gettimeofday (&start,null);//Start Timing------------for (i=0;i<8;i++) {Ch[i] = i;//start 8 threads Ret=pthread_      Create (_id+i,null, (void *) testssd1,ch+i);  if (ret!=0) {printf ("Create pthread error!\n");      return-1;  }} pthread_join (_id[0],null);      Wait for the respective to thread end Pthread_join (_id[1],null);      Pthread_join (_id[2],null);      Pthread_join (_id[3],null);      Pthread_join (_id[4],null);Pthread_join (_id[5],null);      Pthread_join (_id[6],null);      Pthread_join (_id[7],null); Gettimeofday (&end, NULL);//stop timing-------------speed = 1.0* (end.tv_sec-start.tv_sec) + (END.TV_USEC-START.TV_USEC) /1000000.0;//time printf ("SSD write speed:%6.5fmb/s (%6.5fsec) \ n", 256.0*8/speed,speed);           //Tempo printf ("This is SSD Speed Test over!\n\n"); return 0;}

Write Test Run Results:

#./test
# gcc Ssd_test.c-o test-lpthread
#./test
SSD Speed Test begin!

SSD4 Test over!
SSD0 Test over!
SSD6 Test over!
SSD1 Test over!
SSD5 Test over!
SSD7 Test over!
SSD2 Test over!
SSD3 Test over!
SSD Write speed:1563.73594mb/s (1.30968SEC)
SSD Speed Test over!

Read Test Run Results:

#./test

SSD Speed Test begin!

SSD1 Test over!
SSD7 Test over!
SSD3 Test over!
SSD2 Test over!
SSD4 Test over!
SSD5 Test over!
SSD6 Test over!
SSD0 Test over!
SSD Read speed:5915.16042mb/s (0.34623SEC)
SSD Speed Test over!






SSD Electronic disk speed detection under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.