Linux ssd electronic disk speed detection and linuxssd electronic detection

Source: Internet
Author: User

Linux ssd electronic disk speed detection and linuxssd electronic detection

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 ); // 8 MB each time, 256 MB 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) {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 SSD Speed test begin! \ 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 the buffer pbuffer [I] = I & 0xff; gettimeofday (& start, NULL ); // start timing ------------ for (I = 0; I <8; I ++) {ch [I] = I; // start eight 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 until each thread ends 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.5 fsec) \ n ", 256.0*8/speed, speed); // Speed printf (" this is SSD speed test over! \ N "); return 0 ;}

Write test 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.73594 MB/S (1.30968sec)
SSD Speed test over!

Read test 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: 2315.16042 MB/S (0.20.23sec)
SSD Speed test over!






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.