日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

python性能测试方法_Python实现测试磁盘性能的方法

發(fā)布時(shí)間:2025/3/20 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python性能测试方法_Python实现测试磁盘性能的方法 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

本文實(shí)例講述了Python實(shí)現(xiàn)測(cè)試磁盤(pá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)

希望本文所述對(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全棧開(kāi)發(fā)教程

全棧 100W+

主講:Peter-Zhu 輕松幽默、簡(jiǎn)短易學(xué),非常適合PHP學(xué)習(xí)入門(mén)

玉女心經(jīng)-web前端開(kāi)發(fā)教程

入門(mén) 50W+

主講:滅絕師太 由淺入深、明快簡(jiǎn)潔,非常適合前端學(xué)習(xí)入門(mén)

天龍八部-實(shí)戰(zhàn)開(kāi)發(fā)教程

實(shí)戰(zhàn) 80W+

主講:西門(mén)大官人 思路清晰、嚴(yán)謹(jǐn)規(guī)范,適合有一定web編程基礎(chǔ)學(xué)習(xí)

總結(jié)

以上是生活随笔為你收集整理的python性能测试方法_Python实现测试磁盘性能的方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。