日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

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

發布時間:2025/3/20 python 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python性能测试方法_Python实现测试磁盘性能的方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文實例講述了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程序設計有所幫助。

本文原創發布php中文網,轉載請注明出處,感謝您的尊重!

相關文章

相關視頻

網友評論

文明上網理性發言,請遵守 新聞評論服務協議我要評論

立即提交

專題推薦獨孤九賤-php全棧開發教程

全棧 100W+

主講:Peter-Zhu 輕松幽默、簡短易學,非常適合PHP學習入門

玉女心經-web前端開發教程

入門 50W+

主講:滅絕師太 由淺入深、明快簡潔,非常適合前端學習入門

天龍八部-實戰開發教程

實戰 80W+

主講:西門大官人 思路清晰、嚴謹規范,適合有一定web編程基礎學習

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。