473,748 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python versus Perl

Dear all,

I'm currently comparing Python versus Perl to use in a project that
involved a lot of text processing. I'm trying to determine what the most
efficient language would be for our purposes. I have to admit that,
although I'm very familiar with Python, I'm complete Perl noob (and I
hope to stay one) which is reflected in my questions.

I know that the web offers a lot of resources on Python/Perl
differences. But I couldn't find a satisfying answer to my questions:

1 - How does the speed of execution of Perl compares to that of Python?

2 - Regular Expressions are a valuable tool in text processing. I have
noticed that Regular Expressions are executed very fast in Python. Does
anybody know whether Python executes RE faster than Perl does?

3 - In my opinion Python is very well suited for text processing. Does
Perl have any advantages over Python in the field of textprocessing
(like a larger standard library maybe).

I hope somebody can answer my questions. Of course, every remark and tip
on Python/Perl in texprocessing is most welcome.

With kind regards,
Dieter

Sep 6 '05 #1
9 4519
Hi!
[...] 1 - How does the speed of execution of Perl compares to that of Python?


This might not answer your question, but I found "The Computer Language
Shootout Benchmarks" quite interesting (and fun). Python to Perl
comparison can be found at

http://shootout.alioth.debian.org/be...n&sort=fullcpu

Regards,
Matthias

Sep 6 '05 #2
Dieter Vanderelst wrote:
Dear all,

I'm currently comparing Python versus Perl to use in a project that
involved a lot of text processing. I'm trying to determine what the
most efficient language would be for our purposes. I have to admit
that, although I'm very familiar with Python, I'm complete Perl noob
(and I hope to stay one) which is reflected in my questions.

I know that the web offers a lot of resources on Python/Perl
differences. But I couldn't find a satisfying answer to my questions:

1 - How does the speed of execution of Perl compares to that of
Python?
Much of a muchness in my experience.(Qua litative, not quantative)
2 - Regular Expressions are a valuable tool in text processing. I have
noticed that Regular Expressions are executed very fast in Python.
Does anybody know whether Python executes RE faster than Perl does?
3 - In my opinion Python is very well suited for text processing. Does
Perl have any advantages over Python in the field of textprocessing
(like a larger standard library maybe).
These two are related. If you're writing code and you expect to be
using *a lot* of regular expression[*] type code then you may find perl
more convenient.
[*] That /might/ suggest you're taking the wrong approach mind you...

Python, for me, tends to be more readable, both immediately after
writing and if I go back to a year later - for maintenance, extension
etc.

Personally I like both languages for day in day out use, but these days
tend to choose python if I think I'm likely to want to modify or extend
the code. With the exception being where I'm doing heavy text
processing work that I think will be more maintainable in perl, or I'm
really sure I won't have to maintain it. (eg quick and dirty scripts)

One side effect of perl usage though is that due to them being easy to
use and convenient, they can get over used. (Rather than thinking
"what's the best way of solving this problem", people can end up
thinking "What regular expression can solve this problem" - which isn't
ideal)

Your comment """I'm complete Perl noob (and I hope to stay one) """
would suggest to me that if you really feel that way, stay that way :-)
(Though personally I do like learning new programming languages, since
you get more idioms and tools under your belt that way.)
I hope somebody can answer my questions. Of course, every remark and
tip on Python/Perl in texprocessing is most welcome.


In case you're not aware there's the book "Text Processing in Python" by
David Mertz, which is available online in a "free as in beer" form
which might be of use if you decide python instead of perl.
Michael.
--
Mi************@ rd.bbc.co.uk, http://kamaelia.sourceforge.net/
British Broadcasting Corporation, Research and Development
Kingswood Warren, Surrey KT20 6NP

This message (and any attachments) may contain personal views
which are not the views of the BBC unless specifically stated.

Sep 7 '05 #3
On Wednesday 07 September 2005 04:47 am, Michael Sparks wrote:
Dieter Vanderelst wrote:
I'm currently comparing Python versus Perl to use in a project that
involved a lot of text processing. I'm trying to determine what the
most efficient language would be for our purposes. I have to admit
that, although I'm very familiar with Python, I'm complete Perl noob
(and I hope to stay one) which is reflected in my questions.
Your comment """I'm complete Perl noob (and I hope to stay one) """
would suggest to me that if you really feel that way, stay that way :-)


I missed that on the first reading. IMHO, people love perl *really*
because it was the first language of its type. However, we learned
a lot from that experience, and have since made better languages
in the same general category. The best of these of course, is
Python. ;-)

I felt that way about C, and occasionally Fortran. But I've gotten
over it. ;-)

I took Perl classes after I learned Python, and I haven't found
anything Perl is enough better suited to do that it is worth the
trouble of messing with it. Yes, the one and two liner programs are
nice, but now that six months have passed and I can no longer remember
Perl syntax, it's a lot easier to do it in Python, even if I do wind
up using, say, 4 lines of code.

The biggest distinction I got from looking at Perl from the perspective
of Python is that:

1) Perl makes regular expressions first-class objects, which makes them
really easy to use, and a "beginner" subject in a Perl class.

2) Python makes objects and classes really easy to use, so they are a
"beginner" subject.

However, each can do the other when pressed. So which would you rather
have be easy?

Regular expression program makes huge incomprehensibl e piles of
gobblygook which you forget 10 seconds after you wrote it, while
objects and classes make it easy to understand the structure of
your program.

Even regular expressions are clearer in Python (IMHO) because of the
ability to apply string operations on them. Furthermore, the ready
availability of more direct methods of string manipulation encourages
more optimized and clearer design decisions (in Python if you just
want to find a word, you can just say so, instead of "crafting a
routine regular expression").

Performance is a complete non-issue. Both languages are reasonably
fast, and neither has a clear advantage on real world projects. Python
and Perl are "rivals" precisely because they are very similar in what
they can do.

So I'd second the suggestion to eschew the Perl if you can at all
get away with it. If you're already sold on Python, there's no
reason to question your judgement.

Cheers,
Terry

--
Terry Hancock ( hancock at anansispacework s.com )
Anansi Spaceworks http://www.anansispaceworks.com

Sep 7 '05 #4
* Dieter Vanderelst (2005-09-06 18:03 +0100)
I'm currently comparing Python versus Perl to use in a project that
involved a lot of text processing. I'm trying to determine what the most
efficient language would be for our purposes. I have to admit that,
although I'm very familiar with Python, I'm complete Perl noob (and I
hope to stay one) which is reflected in my questions.

I know that the web offers a lot of resources on Python/Perl
differences. But I couldn't find a satisfying answer to my questions:

1 - How does the speed of execution of Perl compares to that of Python?
Of course Python is faster than Perl. It's the same reason why
Mercedes are faster than BMWs (or was it the other way round?).
2 - Regular Expressions are a valuable tool in text processing. I have
noticed that Regular Expressions are executed very fast in Python. Does
anybody know whether Python executes RE faster than Perl does?
Again: this question doesn't make sense. It's up to you to write your
Regular Expressions fast.
3 - In my opinion Python is very well suited for text processing. Does
Perl have any advantages over Python in the field of textprocessing
(like a larger standard library maybe).

I hope somebody can answer my questions. Of course, every remark and tip
on Python/Perl in texprocessing is most welcome.


http://gnosis.cx/TPiP/

"In case regular expression operations prove to be a genuinely
problematic performance bottleneck in an application, there are
four steps you should take in speeding things up. Try these in
order:

1. Think about whether there is a way to simplify the regular
expressions involved. Most especially, is it possible to
reduce the likelihood of backtracking during pattern
matching? You should always test your beliefs about such
simplification, however; performance characteristics rarely
turn out exactly as you expect.

2. Consider whether regular expressions are -really- needed
for the problem at hand. With surprising frequency, faster
and simpler operations in the [string] module (or,
occasionally, in other modules) do what needs to be done.
Actually, this step can often come earlier than the first
one.

3. Write the search or transformation in a faster and
lower-level engine, especially [mx.TextTools]. Low-level
modules will inevitably involve more work and considerably
more intense thinking about the problem. But
order-of-magnitude speed gains are often possible for the
work.

4. Code the application (or the relevant parts of it) in a
different programming language. If speed is the absolutely
first consideration in an application, Assembly, C, or C++
are going to win. Tools like swig--while outside the scope
of this book--can help you create custom extension modules
to perform bottleneck operations. There is a chance also
that if the problem -really must- be solved with regular
expressions that Perl's engine will be faster (but not
always, by any means)."
Sep 10 '05 #5
Dieter Vanderelst <di************ ***@ugent.be> wrote:
1 - How does the speed of execution of Perl compares to that of Python?
To a first-order approximation, Perl and Python run at the same speed.
They are both interpreted languages with roughly the same kind of control
flow and data structures. The two have wildly different kinds of syntax,
but the underlying machinery is fairly similar.

Don't make a decision on which to use based on execution speed. If you
feel compelled to ignore this advice, then don't make the decision until
you've coded your application in both languages and done careful
benchmarking with realistic data for your application domain.
I have noticed that Regular Expressions are executed very fast in
Python. Does anybody know whether Python executes RE faster than Perl
does?


Same answer as above -- for a first cut, assume they are the same speed.
If you insist on a better answer, do measurements on real data.

The big advantage the Python has over Perl is speed of development and ease
of maintenance (i.e. a year from now, you can still understand what your
own code does).
Sep 10 '05 #6

"Roy Smith" <ro*@panix.co m> wrote in message
news:ro******** *************** @reader1.panix. com...
Dieter Vanderelst <di************ ***@ugent.be> wrote:
1 - How does the speed of execution of Perl compares to that of Python?
To a first-order approximation, Perl and Python run at the same speed.
'Speed of execution' is a feature of an inplementation, not of languages
themselves. Different implementations of Python (for instance, CPython
versus CPython+Psyco) can vary in speed by more than a factor of 10 for
particular blocks of Python code.

(Yes, I know you are comparing the stock standard implementations , but my
point still stands.)
They are both interpreted languages.


To be useful, every language has to be interpreted sometime by something.
In the narrow technical sense that I presume you mean, 'interpretation '
versus 'compilation' is again an implementation feature, not a language
feature. As far as I know, neither Perl nor Python has an implementation
that directly interprets in the way that Basic or tokenized Basic once was.

I am being picky because various people have claimed that Python suffers in
popularity because it is known as an 'interpreted language'. So maybe
advocates should be more careful than we have been to not reinforce the
misunderstandin g.

Terry J. Reedy

Sep 11 '05 #7
Terry Reedy wrote:
[...]
I am being picky because various people have claimed that Python suffers
in popularity because it is known as an 'interpreted language'. So maybe
advocates should be more careful than we have been to not reinforce the
misunderstandin g.


I sometimes wonder if it might help people understand the situation if
people described as "interprete d in the same way Java is" (However I think
that risks confusing things since python doesn't generally come with a JIT
subsystem, yet).

That said, if you do describe it that way, it'd be more accurate to describe
the python binary as a compiler/runtime rather than interpreter since it'd
be more accurate.

After all:
$ python somefile.py

Is very close to being the same as:
$ javac somefile.java
$ java somefile.class

It strikes me as ironic that python would probably gain more credibility
with some circles if it had two binaries like this, even though it'd be a
step backwards from a usability perspective :-)

Personally I agree that any language that is described as interpreted has an
image issue. However I'm not sure who's problem that is - some people claim
it's "Python's problem", however personally I'd view as a problem for the
people who buy into "interprett ed bad, compiled good" argument. After all,
they're the ones limiting themselves, and missing out on a whole class of
languages (of which python is just one of course) !
Michael.

Sep 11 '05 #8

"Michael Sparks" <ms@cerenity.or g> wrote in message
news:43******** **************@ ptn-nntp-reader02.plus.n et...
That said, if you do describe it that way, it'd be more accurate to
describe
the python binary as a compiler/runtime rather than interpreter since
it'd
be more accurate.
If Java calls its runtime bytecode interpreter a 'runtime' rather than
'interpreter', so can we. Ditto, if applicable, to .NET clr. Still more
accurate, I think, is 'intergrated compiler and runtime'.
It strikes me as ironic that python would probably gain more credibility
with some circles if it had two binaries like this, even though it'd be a
step backwards from a usability perspective :-)
Yes. The integration is a practical necessity for interactive mode with
alternative compile and execute. For batch mode, integration consists of
the very nice built-in mini-make.
Personally I agree that any language that is described as interpreted has
an
image issue. However I'm not sure who's problem that is - some people
claim
it's "Python's problem", however personally I'd view as a problem for the
people who buy into "interprett ed bad, compiled good" argument. After
all,
they're the ones limiting themselves, and missing out on a whole class of
languages (of which python is just one of course) !


That has been my response. And as a Python programmer, that is the end of
it. But as a responder/advocate, I am beginning to accept that the
misperception is wide enough to also be a bit my problem. Hence my small
effort for a more effective vocabulary. Thanks for your contribution.

Terry J. Reedy


Sep 11 '05 #9
On Sun, 11 Sep 2005 18:47:14 +0100, Michael Sparks <ms@cerenity.or g>
declaimed the following in comp.lang.pytho n:
I sometimes wonder if it might help people understand the situation if
people described as "interprete d in the same way Java is" (However I think
that risks confusing things since python doesn't generally come with a JIT
subsystem, yet).
I'd probably try pushing the pre-interpretation phase more heavily:
.... compiled to machine code for a virtual machine, just as Java (and
UCSD Pascal).

Heck -- isn't the goal of M$'s .NET to virtualize the entire
computer <G> {Ack -- next we'll find out M$ plans to implement IBM's
VM/CMS with graphical layer <G>}
-- =============== =============== =============== =============== == <
wl*****@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
=============== =============== =============== =============== == <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.ne tcom.com/> <

Sep 11 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
6570
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO FRICKIN' COOL!!! ***MAN*** that would save me a buttload of work and make my life sooooo much easier!" As opposed to minor differences of this feature here, that feature there. Variations on style are of no interest to me. I'm coming at this from a...
13
4031
by: Peter Mutsaers | last post by:
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.
31
4801
by: surfunbear | last post by:
I've read some posts on Perl versus Python and studied a bit of my Python book. I'm a software engineer, familiar with C++ objected oriented development, but have been using Perl because it is great for pattern matching, text processing, and automated testing. Our company is really fixated on risk managnemt and the only way I can do enough testing without working overtime (which some people have ended up doing) is by automating my...
68
5880
by: Lad | last post by:
Is anyone capable of providing Python advantages over PHP if there are any? Cheers, L.
72
5562
by: Gregory Petrosyan | last post by:
Please visit http://www.python.org/peps/pep-0204.html first. As you can see, PEP 204 was rejected, mostly because of not-so-obvious syntax. But IMO the idea behind this pep is very nice. So, maybe there's a reason to adopt slightly modified Haskell's syntax? Something like --> (1,3..10) --> same values as above, but return generator instead of list
6
5372
by: metaperl | last post by:
Hello, I am responsible for converting 30 loosey-goosey Perl scripts into 30 well-documented easy to understand and use Python scripts. No one has said anything in particular about how this should be done, but the end product should be "professional" looking. So, I'm looking for some books and suggestions which will help me write high-quality scripts. I know about object-oriented programming and application configuration and have spent...
4
4348
by: kettle | last post by:
Hi, I am rather new to python, and am currently struggling with some encoding issues. I have some utf-8-encoded text which I need to encode as iso-2022-jp before sending it out to the world. I am using python's encode functions: -- var = var.encode("iso-2022-jp", "replace") print var --
14
2223
by: marcpenninga | last post by:
This is *not* an attempt to start yet another Python-versus- AnyOtherProgrammingLanguage flame war, but I thought people might be interested in this: http://www.tiobe.com/tpci.htm Marc
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4877
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.