国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python實現測試磁盤性能的方法

2019-11-25 17:57:29
字體:
來源:轉載
供稿:網友

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

該代碼做了如下工作:

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代碼如下:

復制代碼 代碼如下:
#!/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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 洛浦县| 和顺县| 柳江县| 杨浦区| 读书| 襄垣县| 平定县| 仁寿县| 离岛区| 土默特右旗| 高平市| 湾仔区| 莒南县| 镇平县| 开化县| 治多县| 佛冈县| 达日县| 右玉县| 长宁县| 长春市| 中卫市| 明星| 延庆县| 衡水市| 高唐县| 新津县| 彭阳县| 岐山县| 旬邑县| 克拉玛依市| 绥棱县| 临夏县| 蓝山县| 女性| 东宁县| 嫩江县| 奉贤区| 南和县| 南和县| 绥德县|