Python實現(xià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代碼如下:
# -*- 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)文章
jupyter notebook 調(diào)用環(huán)境中的Keras或者pytorch教程
這篇文章主要介紹了jupyter notebook 調(diào)用環(huán)境中的Keras或者pytorch教程,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04
python自動化操作之動態(tài)驗證碼、滑動驗證碼的降噪和識別
很多網(wǎng)站登錄都需要輸入驗證碼,如果要實現(xiàn)自動登錄就不可避免的要識別驗證碼,下面這篇文章主要給大家介紹了關(guān)于python自動化操作之動態(tài)驗證碼、滑動驗證碼的降噪和識別,需要的朋友可以參考下2021-08-08
Python編程pytorch深度卷積神經(jīng)網(wǎng)絡(luò)AlexNet詳解
AlexNet和LeNet的架構(gòu)非常相似。這里我們提供了一個稍微精簡版本的AlexNet,去除了當(dāng)年需要兩個小型GPU同時運算的設(shè)計特點2021-10-10
Python greenlet實現(xiàn)原理和使用示例
這篇文章主要介紹了Python greenlet實現(xiàn)原理和使用示例,greenlet是Python中的一個并行處理庫,需要的朋友可以參考下2014-09-09

