最新国产好看的视频,伊人天堂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)文章

最新評論

永定县| 叶城县| 石阡县| 迁安市| 德钦县| 固原市| 武川县| 德州市| 廊坊市| 民乐县| 昭通市| 吉安市| 高阳县| 类乌齐县| 临泉县| 玉屏| 凤翔县| 民县| 抚松县| 庄浪县| 敦化市| 石渠县| 太谷县| 博爱县| 海城市| 重庆市| 壶关县| 通许县| 财经| 锡林浩特市| 荆州市| 额尔古纳市| 万荣县| 霞浦县| 灵川县| 安陆市| 商丘市| 积石山| 奎屯市| 西乌珠穆沁旗| 赤壁市|