python性能测试方法_Python实现测试磁盘性能的方法
本文實(shí)例講述了Python實(shí)現(xiàn)測(cè)試磁盤性能的方法。分享給大家供大家參考。具體如下:
該代碼做了如下工作:
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)
希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
本文原創(chuàng)發(fā)布php中文網(wǎng),轉(zhuǎn)載請(qǐng)注明出處,感謝您的尊重!
相關(guān)文章
相關(guān)視頻
網(wǎng)友評(píng)論
文明上網(wǎng)理性發(fā)言,請(qǐng)遵守 新聞評(píng)論服務(wù)協(xié)議我要評(píng)論
立即提交
專題推薦獨(dú)孤九賤-php全棧開發(fā)教程
全棧 100W+
主講:Peter-Zhu 輕松幽默、簡(jiǎn)短易學(xué),非常適合PHP學(xué)習(xí)入門
玉女心經(jīng)-web前端開發(fā)教程
入門 50W+
主講:滅絕師太 由淺入深、明快簡(jiǎn)潔,非常適合前端學(xué)習(xí)入門
天龍八部-實(shí)戰(zhàn)開發(fā)教程
實(shí)戰(zhàn) 80W+
主講:西門大官人 思路清晰、嚴(yán)謹(jǐn)規(guī)范,適合有一定web編程基礎(chǔ)學(xué)習(xí)
總結(jié)
以上是生活随笔為你收集整理的python性能测试方法_Python实现测试磁盘性能的方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: java 事务 数据库 事务_Java数
- 下一篇: c mysql 内存泄露_c代码连接my
