• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python实现测试磁盘性能的方法

Python实现测试磁盘性能的方法

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python性能测试,python性能分析与优化,python性能,高性能python,python高性能编程 pdf等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了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代码如下:
# -*- 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)</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • Python性能提升之延迟初始化
  • Python 性能优化技巧总结
  • python 性能提升的几种方法
  • Python实现测试磁盘性能的方法
  • Python性能优化技巧
  • Python 代码性能优化技巧分享
  • Python 代码性能优化技巧分享

相关文章

  • Python中用函数作为返回值和实现闭包的教程
  • python实现sublime3的less编译插件示例
  • 详解Python的Django框架中的Cookie相关处理
  • Python multiprocessing.Manager介绍和实例(进程间共享数据)
  • 详解Python中类的定义与使用
  • Python中的两个内置模块介绍
  • Python写入CSV文件的方法
  • python同时给两个收件人发送邮件的方法
  • windows系统中python使用rar命令压缩多个文件夹示例
  • python实现的文件同步服务器实例

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Django发送html邮件的方法
    • Python深入学习之闭包
    • 双向RNN:bidirectional_dynamic_rnn()函数的使用详解
    • 详解python中xlrd包的安装与处理Excel表格
    • 在Python中使用dict和set方法的教程
    • PYTHON压平嵌套列表的简单实现
    • Python找出list中最常出现元素的方法
    • Python用模块pytz来转换时区
    • 详解Python的Django框架中的Cookie相关处理
    • Python中用altzone()方法处理时区的教程

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有