最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python實現(xiàn)測試磁盤性能的方法

 更新時間:2015年03月12日 11:32:29   作者:鑒客  
這篇文章主要介紹了Python實現(xiàn)測試磁盤性能的方法,涉及Python對硬件的相關(guān)操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了Python實現(xiàn)測試磁盤性能的方法。分享給大家供大家參考。具體如下:

該代碼做了如下工作:

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

bench.py代碼如下:

復(fù)制代碼 代碼如下:
#!/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)

希望本文所述對大家的Python程序設(shè)計有所幫助。

相關(guān)文章

最新評論

金塔县| 汕尾市| 进贤县| 双峰县| 资源县| 临猗县| 平原县| 六盘水市| 崇阳县| 彭山县| 鸡泽县| 福建省| 美姑县| SHOW| 望城县| 张掖市| 清徐县| 绥芬河市| 云梦县| 丰都县| 元谋县| 邻水| 增城市| 泰来县| 龙井市| 淄博市| 嘉祥县| 金门县| 苏尼特右旗| 马边| 金湖县| 乐业县| 呼图壁县| 朔州市| 阿勒泰市| 汕尾市| 阿荣旗| 锡林浩特市| 绿春县| 玉田县| 新宁县|