Perl-python regex-performance comparison

I

Ivan

Hello everyone,

I know this is not a direct python question, forgive me for that, but
maybe some of you will still be able to help me. I've been told that
for my application it would be best to learn a scripting language, so
I looked around and found perl and python to be the nice. Their syntax
and "way" is not similar, though.
So, I was wondering, could any of you please elaborate on the
following, as to ease my dilemma:

1. Although it is all relatively similar, there are differences
between regexes of these two. Which do you believe is the more
powerful variant (maybe an example) ?

2. They are both interpreted languages, and I can't really be sure how
they measure in speed. In your opinion, for handling large files,
which is better ?
(I'm processing files of numerical data of several hundred mb - let's
say 200mb - how would python handle file of such size ? As compared to
perl ?)

3. This last one is somewhat subjective, but what do you think, in the
future, which will be more useful. Which, in your (humble) opinion
"has a future" ?

Thank you for all the info you can spare, and expecially grateful for
the time in doing so.
-- Ivan
 
C

Chris Rebert

Hello everyone,

I know this is not a direct python question, forgive me for that, but
maybe some of you will still be able to help me. I've been told that
for my application it would be best to learn a scripting language, so
I looked around and found perl and python to be the nice. Their syntax
and "way" is not similar, though.
So, I was wondering, could any of you please elaborate on the
following, as to ease my dilemma:

1. Although it is all relatively similar, there are differences
between regexes of these two. Which do you believe is the more
powerful variant (maybe an example) ?

I would think that either they're currently equal in power or Perl's
are just slightly more powerful, as pretty much all languages have
basically copied Perl's regular expressions almost exactly. If you're
talking about Perl6, then combined with the new "rules" feature it's
much more powerful; however, like Perl's regular expressions, someone
will probably write a library like pcre that implements it for all
other languages, so it'll probably just be a matter of syntax.
2. They are both interpreted languages, and I can't really be sure how
they measure in speed. In your opinion, for handling large files,
which is better ?
(I'm processing files of numerical data of several hundred mb - let's
say 200mb - how would python handle file of such size ? As compared to
perl ?)

They're probably both about the same. Your problem is probably
IO-bound, so the slowness of either language will likely be made
irrelevant by the comparative slowness of your hard disk. If you
really care about maximum speed here, you should probably write a C
extension for the most intensive part of your algorithm (fairly easy
to do with Python, probably about the same with Perl), though Python
also has Psyco and Cython available as other ways to speed up your
program without resorting to C; don't know if Perl has any similar
tools.
3. This last one is somewhat subjective, but what do you think, in the
future, which will be more useful. Which, in your (humble) opinion
"has a future" ?

Python is already well on its way to a smooth transition to Python 3.0
(Python's Perl6 equivalent) with few drastic changes to the language;
most of the changes are pretty incremental but just happen to break
backward compatibility; and the resulting language is still quite
clearly identifiable as Python.
Perl, on the other hand, is currently quagmired in a long,
indeterminate wait for the epic and drastically-revised Perl 6 to be
released.
They both have a future, but Python's definitely appears more secure
at this point. It's more wait-and-see with Perl. But take this with a
grain of salt due to the obvious pro-Python bias you'll get on this
list.

Cheers,
Chris
 
M

MRAB

Chris said:
I would think that either they're currently equal in power or Perl's
are just slightly more powerful, as pretty much all languages have
basically copied Perl's regular expressions almost exactly. If you're
talking about Perl6, then combined with the new "rules" feature it's
much more powerful; however, like Perl's regular expressions, someone
will probably write a library like pcre that implements it for all
other languages, so it'll probably just be a matter of syntax.
Python 2.7's regex will include possessive quantifiers, atomic groups,
variable-length lookbehinds, and Unicode properties (at least the common
ones), amongst other things.
 
S

Steve Holden

Ivan said:
Hello everyone,

I know this is not a direct python question, forgive me for that, but
maybe some of you will still be able to help me. I've been told that
for my application it would be best to learn a scripting language, so
I looked around and found perl and python to be the nice. Their syntax
and "way" is not similar, though.
So, I was wondering, could any of you please elaborate on the
following, as to ease my dilemma:
http://isperldeadyet.com/

regards
Steve
 
V

Vlastimil Brom

2009/3/3 MRAB said:
Python 2.7's regex will include possessive quantifiers, atomic groups,
variable-length lookbehinds, and Unicode properties (at least the common
ones), amongst other things.

Wow, that's excellent news!
Many thanks for all your efforts to enhance the re capabilities in Python!

vbr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top