How to test disk performance using Python

Source: Internet
Author: User
This article describes how to test disk performance using Python. it involves Python's hardware-related operating skills and has some reference value, for more information about how to test disk performance using Python, see the following example. Share it with you for your reference. The details are as follows:

The code does the following:

Create 300000 files (512B to 1536B) with data from/dev/urandom
Rewrite 30000 random files and change the size.
Read 30000 sequential files
Read 30000 random files
Delete all files
Sync and drop cache after every step

Pipeline. py code is as follows:

The code is as follows:

#! /Usr/bin/python
#-*-Coding: UTF-8 -*-
Filecount = 300000
Filesize = 1024
Import random, time
From OS import system
Flush = "sudo su-c 'sync; echo 3>/proc/sys/vm/drop_caches '"
Randfile = open ("/dev/urandom", "r ")
Print "\ ncreate test folder :"
Starttime = time. time ()
System ("rm-rf test & mkdir test ")
Print time. time ()-starttime
System (flush)
Print "\ ncreate files :"
Starttime = time. time ()
For I in xrange (filecount ):
Rand = randfile. read (int (filesize * 0.5 + filesize * random. random ()))
Outfile = open ("test/" + unicode (I), "w ")
Outfile. write (rand)
Print time. time ()-starttime
System (flush)
Print "\ nrewrite files :"
Starttime = time. time ()
For I in xrange (int (filecount/10 )):
Rand = randfile. read (int (filesize * 0.5 + filesize * random. random ()))
Outfile = open ("test/" + unicode (int (random. random () * filecount), "w ")
Outfile. write (rand)
Print time. time ()-starttime
System (flush)
Print "\ nread linear :"
Starttime = time. time ()
For I in xrange (int (filecount/10 )):
Infile = open ("test/" + unicode (I), "r ")
Outfile. write (infile. read ());
Print time. time ()-starttime
System (flush)
Print "\ nread random :"
Starttime = time. time ()
Outfile = open ("/dev/null", "w ")
For I in xrange (int (filecount/10 )):
Infile = open ("test/" + unicode (int (random. random () * filecount), "r ")
Outfile. write (infile. read ());
Print time. time ()-starttime
System (flush)
Print "\ ndelete all files :"
Starttime = time. time ()
System ("rm-rf test ")
Print time. time ()-starttime
System (flush)

I hope this article will help you with Python programming.

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.