当前位置: 首页 > news >正文

南阳微网站制作开发公司制度

南阳微网站制作,开发公司制度,购物网站后台管理模板,抖音引流推广软件我正在编写一个简单的应用程序#xff0c;它将大文本文件拆分为较小的文件#xff0c;并且我已经编写了2个版本#xff0c;一个使用列表#xff0c;另一个使用生成器。我使用memory_profiler模块对这两个版本进行了概要分析#xff0c;并清楚地显示了生成器版本的更好的内…我正在编写一个简单的应用程序它将大文本文件拆分为较小的文件并且我已经编写了2个版本一个使用列表另一个使用生成器。我使用memory_profiler模块对这两个版本进行了概要分析并清楚地显示了生成器版本的更好的内存效率但是在对使用生成器的版本进行概要分析时这很奇怪这增加了执行时间。下面的演示解释了我的意思 使用列表版本 frommemory_profilerimportprofileprofile()defmain():file_nameinput(Enter the full path of file you want to split into smaller inputFiles: )input_fileopen(file_name).readlines()num_lines_origlen(input_file)partsint(input(Enter the number of parts you want to split in: ))output_files[(file_namestr(i))foriinrange(1,parts1)]st0pint(num_lines_orig/parts)edpforiinrange(parts-1):withopen(output_files[i],w)asOF:OF.writelines(input_file[st:ed])sted edstpwithopen(output_files[-1],w)asOF:OF.writelines(input_file[st:])if__name____main__:main() 与分析器一起运行时 $ time py36Splitting\ text\ files_BAD_usingLists.pyEnterthe full path of file you want to split into smaller inputFiles:/apps/nttech/rbhanot/Downloads/test.txtEnterthe number of parts you want to splitin:3Filename:Splittingtext files_BAD_usingLists.pyLine# Mem usage Increment Line Contents647.8MiB0.0MiBprofile()7defmain():847.8MiB0.0MiBfile_nameinput(Enter the full path of file you want to split into smaller inputFiles: )9107.3MiB59.5MiBinput_fileopen(file_name).readlines()10107.3MiB0.0MiBnum_lines_origlen(input_file)11107.3MiB0.0MiBpartsint(input(Enter the number of parts you want to split in: ))12107.3MiB0.0MiBoutput_files[(file_namestr(i))foriinrange(1,parts1)]13107.3MiB0.0MiBst014107.3MiB0.0MiBpint(num_lines_orig/parts)15107.3MiB0.0MiBedp16108.1MiB0.7MiBforiinrange(parts-1):17107.6MiB-0.5MiBwithopen(output_files[i],w)asOF:18108.1MiB0.5MiBOF.writelines(input_file[st:ed])19108.1MiB0.0MiBsted20108.1MiB0.0MiBedstp2122108.1MiB0.0MiBwithopen(output_files[-1],w)asOF:23108.1MiB0.0MiBOF.writelines(input_file[st:])real0m6.115suser0m0.764ssys0m0.052s 在没有分析器的情况下运行 $ time py36Splitting\ text\ files_BAD_usingLists.pyEnterthe full path of file you want to split into smaller inputFiles:/apps/nttech/rbhanot/Downloads/test.txtEnterthe number of parts you want to splitin:3real0m5.916suser0m0.696ssys0m0.080s 现在使用发电机 profile()defmain():file_nameinput(Enter the full path of file you want to split into smaller inputFiles: )input_fileopen(file_name)num_lines_origsum(1for_ininput_file)input_file.seek(0)partsint(input(Enter the number of parts you want to split in: ))output_files((file_namestr(i))foriinrange(1,parts1))st0pint(num_lines_orig/parts)edpforiinrange(parts-1):filenext(output_files)withopen(file,w)asOF:for_inrange(st,ed):OF.writelines(input_file.readline())sted edstpifnum_lines_orig-ed filenext(output_files)withopen(file,w)asOF:for_inrange(st,ed):OF.writelines(input_file.readline())if__name____main__:main() 使用分析器选项运行时 $ time py36-m memory_profilerSplitting\ text\ files_GOOD_usingGenerators.pyEnterthe full path of file you want to split into smaller inputFiles:/apps/nttech/rbhanot/Downloads/test.txtEnterthe number of parts you want to splitin:3Filename:Splittingtext files_GOOD_usingGenerators.pyLine# Mem usage Increment Line Contents447.988MiB0.000MiBprofile()5defmain():647.988MiB0.000MiBfile_nameinput(Enter the full path of file you want to split into smaller inputFiles: )747.988MiB0.000MiBinput_fileopen(file_name)847.988MiB0.000MiBnum_lines_origsum(1for_ininput_file)947.988MiB0.000MiBinput_file.seek(0)1047.988MiB0.000MiBpartsint(input(Enter the number of parts you want to split in: ))1148.703MiB0.715MiBoutput_files((file_namestr(i))foriinrange(1,parts1))1247.988MiB-0.715MiBst01347.988MiB0.000MiBpint(num_lines_orig/parts)1447.988MiB0.000MiBedp1548.703MiB0.715MiBforiinrange(parts-1):1648.703MiB0.000MiBfilenext(output_files)1748.703MiB0.000MiBwithopen(file,w)asOF:1848.703MiB0.000MiBfor_inrange(st,ed):1948.703MiB0.000MiBOF.writelines(input_file.readline())202148.703MiB0.000MiBsted2248.703MiB0.000MiBedstp2348.703MiB0.000MiBifnum_lines_orig-ed
http://www.zqtcl.cn/news/739923/

相关文章:

  • 网站制作技术建设部网站监理工程师查询
  • 自助做网站嘉兴做网站优化
  • 淘宝客网站开发视频新手 网站建设 书籍
  • 在哪个网站做旅游攻略好做推广便宜的网站
  • 濮阳做网站推广做网站为什么要建站点
  • 摄影网站建设需求分析wordpress一键关注
  • 做学历的网站什么是短视频营销
  • 网站线上推广方式广告海外推广
  • 免费网站注册申请海口网站seo
  • ppt免费下载雷锋网站WordPress5分钟建站
  • 商店网站制作做签名照的网站
  • 自己制作一个网站广州自助网站制作
  • 个人网站吗wordpress超精简主题
  • 手机版免费申请微网站wordpress 跳转链接
  • 网站建设与管理好吗广州白云最新消息
  • 织梦动漫网站模版wordpress 页面文章列表
  • 东莞做网站沃德长沙市网站开发
  • 哪些网站做的最好厦门网站建设网站
  • 网站安全事件应急处置机制建设类似百度的网站
  • 内蒙古知名网站建设网站测速工具
  • 怎样建立网站赚钱怎么登录住建局官网
  • 建站自学网页转向功能网站
  • 网站都有什么费用做酒店网站有哪些目录
  • 本地郑州网站建设东莞网站优化中易
  • 动态域名可以建网站德州公司做网站
  • 深圳建设银行官方网站wordpress 添加qq
  • 甘肃第九建设集团公司网站网站对企业的好处
  • 论坛网站建设规划书公司网站建设与设计制作
  • 做棋牌游戏网站犯法吗如何进行搜索引擎的优化
  • 常见的网站首页布局有哪几种陈光锋网站运营推广新动向