Python过滤脚本很慢 [英] Python slow for filter scripts

查看:79
本文介绍了Python过滤脚本很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


到目前为止,我主要在Perl中编写简单的过滤器脚本,例如


while(<>){

#做$ _,正则表达式匹配,替换等等。

打印;

}


现在我学习了Python并且更喜欢它作为一种语言。


然而,我在Perl中尝试了最简单的(<>){print;}与

Python,只是从stdin到stdout的副本,看看基本的

过滤器有多快。


我发现我的(linux)PC,Python版本慢了4倍。


这是正常的,它是否取消了Python的简单过滤脚本资格?

Hello,

Up to now I mostly wrote simple filter scripts in Perl, e.g.

while(<>) {
# do something with $_, regexp matching, replacements etc.
print;
}

Now I learned Python and like it much more as a language.

However, I tried the most simple while(<>) {print;} in Perl versus
Python, just a copy from stdin to stdout, to see how fast the basic
filter can be.

I found that on my (linux) PC, the Python version was 4 times slower.

Is that normal, does it disqualify Python for simple filter scripts?

推荐答案

_,正则表达式匹配,替换等。

打印;

}


现在我学习了Python并且更喜欢它作为一种语言。


然而,我在Perl中尝试了最简单的(<>){print;}与

Python,只是一个副本m stdin到stdout,看看基本的b / b
过滤器有多快。


我发现在我的(linux)PC上,Python版本是4比较慢。


这是正常现象吗,它是否会取消Python的简单过滤脚本资格?
_, regexp matching, replacements etc.
print;
}

Now I learned Python and like it much more as a language.

However, I tried the most simple while(<>) {print;} in Perl versus
Python, just a copy from stdin to stdout, to see how fast the basic
filter can be.

I found that on my (linux) PC, the Python version was 4 times slower.

Is that normal, does it disqualify Python for simple filter scripts?




Peter Mutsaers < pl*@gmx.li>在留言中写道

news:97 ************************** @ posting.google.c om ...

"Peter Mutsaers" <pl*@gmx.li> wrote in message
news:97**************************@posting.google.c om...
但是,我尝试了最简单的while(<>){print;}在Perl中与
Python,只是从stdin到stdout的副本,看看基本有多快过滤器可以是。

我发现在我的(linux)PC上,Python版本慢了4倍



那里有几种方法可以在Python中复制文件。有些比其他人快得多b / b
。我相信''for file in file:print line''可能是使用python代码最快
。还有shutil.copyfile(src,dst)或

其他变种之一。您使用了哪一个?

这是正常的,它是否取消了Python的简单过滤脚本资格?
However, I tried the most simple while(<>) {print;} in Perl versus
Python, just a copy from stdin to stdout, to see how fast the basic
filter can be.

I found that on my (linux) PC, the Python version was 4 times slower.

There are several ways to copy a file in Python. Some are much faster
than others. I believe ''for line in file: print line'' might be
fastest with python code. There is also shutil.copyfile(src,dst) or
one of other variants. Which did you use?
Is that normal, does it disqualify Python for simple filter scripts?




我读过Perl针对其进行了优化文件读/写的方式是

Python不是,所以这可能不是你的实际应用程序的最具代表性的比较

。在任何情况下,相对速度的相关性取决于

绝对速度(考虑千分之几与小时数)。


Terry J. Reedy



I have read that Perl is optimized for file read/write in a way that
Python is not, so this may not be most representative comparison for
your actual app. In any case, relevance of relative speed depends on
absolute speed (think about milleseconds versus hours).

Terry J. Reedy


Peter Mutsaers写道:
Peter Mutsaers wrote:
你好,

到目前为止,我主要在Perl编写简单的过滤脚本,例如

while(<>){
#做某事
Hello,

Up to now I mostly wrote simple filter scripts in Perl, e.g.

while(<>) {
# do something with


这篇关于Python过滤脚本很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆