LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Python or Perl (https://www.linuxquestions.org/questions/programming-9/python-or-perl-406345/)

mrcheeks 10-27-2006 07:36 AM

I meant the runtime execution not the development time

introuble 10-27-2006 12:03 PM

Anyway, to save you the time of checking out other threads on this forum and what not others, I'll make a long story short:

Python > Perl.


[Joking!.. well.. not to say it's not.]

krizzz 10-27-2006 01:29 PM

Definitely Perl.
First of all - much faster.
You can prove it yourself by writing some classic test and comparing the results. You can also find comparisons in the Internet.

slantoflight 10-27-2006 07:06 PM

Quote:

Originally Posted by krizzz
Definitely Perl.
First of all - much faster.
You can prove it yourself by writing some classic test and comparing the results. You can also find comparisons in the Internet.

So I found this
http://shootout.alioth.debian.org/gp4/python.php

These examples are scientific in nature, and come the closest to being 'practical' benchmarks.

And it really doesn't seem to support you're argument, "much faster".

Outside of a few suspicpious spikes, they really seem comparable

Removing the two largest deviations

n-body test(which neither languages did a particularly good job on).
fasta(python executes 1.5 fasters but uses 10.9x the memory)

Python has 19 instances of being 'x' faster whereas perl has 19 instances.

averaging the speeds on x faster.
Python was 1.8 whereas perl was 1.873684211.

The only 2 benchmarks that place perl dramatically ahead of python
where the same benchmarks that proved either language was impractical if speed was the primary concern.

Besides if you chose either, python or perl, chances are the speed of execution is not on the top of your concern list.

If it is though, and you really want the fastest interpreter, you must ask yourself this question.

Is perl's minute speed advantage worth dealing with its idosyncrasies? Are you going to like the way it looks, after realising a few months later you need to make some changes.

krizzz 10-29-2006 07:29 PM

How about this benchmark http://furryland.org/~mikec/bench/

slantoflight 10-30-2006 03:37 AM

Quote:

Originally Posted by krizzz
How about this benchmark http://furryland.org/~mikec/bench/


This page is outdated, ran by one person, no longer maintained and some of the results are clearly erroneous.

for example the console test is waaaaaaaaaay off.

simple verification(i'm assuming this is what the author did as well)

time perl console.pl >> /dev/null
real 0m1.580s
time python console.pl >>/dev/null
real 0m3.295s



this test shows, atleast on my computer, perl leading by a whopping two seconds.

I got similar results with i/o
real 0m1.865s perl
real 0m3.461s python


The "speed" test shows the interpreters being near identical in speed on my computer.

In the self-deprecating intro paragraph, the author even admits these are flawed benchmarks.

Plus this all without compiling the python script to intermediate code and using the pysco module.

You've been misinformed about perl, I believe. It does not have any significant speed advantages over python.

ghostdog74 10-30-2006 05:56 AM

For the console test,
if i change the python code to
Code:

x = 0
for i in xrange(1000000):
        x = x + i

and the perl one to

Code:

$x=0;
for $i (0 .. 1000000-1) {
        $x=$x + $i;
}

the speed of execution is almost comparable.

output
Code:


bash-2.03$ time perl console.pl >>/dev/null

real    0m0.761s
user    0m0.760s
sys    0m0.020s
bash-2.03$ time python -S console.py >>/dev/null

real    0m1.280s
user    0m1.240s
sys    0m0.030s

I suspect its the different implementaion of print() function.
what are your views?

soggycornflake 10-30-2006 10:43 AM

Quote:

Definitely Perl.
First of all - much faster.
It may execute a few % faster, but it's an order of magnitude slower to write and maintain. Computers get faster, humans don't (much). I find writing Perl tedious, which is an adjective I could never imagine using about Python
(except in relation to not having it). I guess that sound extremely biased, but that is just my experience.

Quote:

Originally Posted by ghostdog74
Quote:
Originally Posted by R00ts
The only thing I dislike about Python is the forced indentation (I feel that's not the job of a programming language), but its much more sane than Perl IMHO.
Welcome to Python
and you shouldn't have to dislike it because of the indentation. After a while you will get used to it.

Indeed. Initially I didn't like the language screwing with my indentation preferences, but after a few weeks, you forget about it.

Quote:

Originally Posted by ghostdog74
Sometimes when i switch back to writing Perl or other languages, my fingers automatically will press the tab key to indent every time i reach a new line..haha

Ha. A feeling I know well. The subconcious soon absorbs a languages idiosyncracies (except for perl, of course, which is just absurd). :)

mrcheeks 10-30-2006 04:59 PM

Python is simple, easier but slower. If speed isn't a concern, I suggest Python. I am starting to learn Perl as well. It is good to learn how to read it as lots of people are written in Perl. I am converting few applications from Java to Python in the meantime : enough libraries to develop with, simple to use + to maintain.
When your program requires lots of performance(graphics drawing, etc.) and runtime speed/processing is the main concern, use C or C++, not Java, Python, Perl, etc.

mrcheeks 10-31-2006 06:45 PM

A simple benchmark shows that pure C is faster. For the other languages it depends on how you code it, compile it(optimisations flags), if you run precompiled code, etc.
Code:

mrcheeks:~/Tests/Perl> time $cwd/test.pl
hello
0.006u 0.001s 0:00.00 0.0%      0+0k 0+0io 0pf+0w
mrcheeks:~/Tests/Perl> time $cwd/testcpp
hello
0.002u 0.000s 0:00.00 0.0%      0+0k 0+0io 0pf+0w
mrcheeks:~/Tests/Perl> time $cwd/testcpp
hello
0.001u 0.000s 0:00.00 0.0%      0+0k 0+0io 0pf+0w
mrcheeks:~/Tests/Perl> time $cwd/testcc
Hello, world!
0.000u 0.001s 0:00.00 0.0%      0+0k 0+0io 0pf+0w
mrcheeks:~/Tests/Perl> time $cwd/test.pl
hello
0.003u 0.005s 0:00.00 0.0%      0+0k 0+0io 0pf+0w
mrcheeks:~/Tests/Perl> time python $cwd/test.py
hello
0.018u 0.006s 0:00.00 0.0%      0+0k 0+0io 0pf+0w
mrcheeks:~/Tests/Perl> time java test
hello
0.119u 0.041s 0:00.42 35.7%    0+0k 0+0io 7pf+0w

The C version
Code:

#include <stdio.h>
#include <stdlib.h>

/* Main Function
*  Purpose: Controls our program, prints Hello, World!
*  Input: None
*  Output: Returns Exit Status
*/

int main() {
        (void)printf("Hello, world!\n");
        return EXIT_SUCCESS;
}

The C++ version
Code:

#include <iostream>
using namespace std;

int main(){
        cout << "hello" << endl;
        return 0;
}

The Perl version
Code:

#!/usr/bin/env perl
printf "hello\n";

The Python version
Code:

#!/usr/bin/python
print 'hello'

The Java version
Code:

public class test{
        public static void main(String argv[]){
                System.out.println("hello");
        }
}


Fred_213 11-01-2006 03:57 PM

As a final note...
 
Being a python programmer in industry for testing aerospace equipment, I found that python is merely precompiled C libraries where upon execution, byte-code is generated the first time through and subsequent runs are just that much faster. If speed is an issue one must eliminate the abstracted interpreter layer and work at the os level and using compiled native code. Python excels for time-to-market coding speed and extensibility via custom package creation. I believe I read a post that python lacks libraries which is hardly the case. It actually has available, quite an array of packages that allow a programmer to interface to all types of databases, applications etc. Love the neat coding standard of indenting since I've seen such horid coding practices which are not permitted in python. These are all good things that make it easier and less risky to implement. You can also build a windows executable out of your python scripts and run them like a native program.

soggycornflake 11-03-2006 09:55 AM

Quote:

Originally Posted by mrcheeks
I am starting to learn Perl as well. It is good to learn how to read it as lots of people are written in Perl.

Lots of people are written in perl !!!??? :confused:

mrcheeks 11-03-2006 01:58 PM

hehehe.... I must have been tired. .... I meant programs...

xlinuks 12-22-2006 01:11 AM

mrcheeks
Quote:

When your program requires lots of performance(graphics drawing, etc.) and runtime speed/processing is the main concern, use C or C++, not Java, Python, Perl, etc.
Anyone knows that, however, Java 6 has been newly released, and, surprisingly I'm quite happy (for the first time!) with its speed, especially with the GUI (and ImageIO) performance. There are significant changes between Java 5 and 6. I was thinking to start learning C just because the GUIs didn't work fast enough, now, however, at least for me, the Java (Drawing and other GUI stuff) speed seems pretty fast (not to mention the other new features). The only BIG thing I'm really missing - rich DESKTOP libraries (to use pure Java to make transparent windows, make the app launch at system startup and a few important issues), I guess I'll create a thread on this issue.

eerok 12-22-2006 09:54 AM

Python and perl are both good languages. I was writing text-processing utilities in C because I was familiar with it, but then I decided I'd try perl since it's designed for the tasks I'm doing. It's working out very well. I could've gone with python, too, and in fact it was a close decision.

It's true that perl code can be baroque and opaque, but it doesn't have to be. I think it's also true that it's easy to get started with perl and difficult to master it. For someone just wanting to learn a language for it's own sake, I'd recommend python. But with perl, if you have a task at hand that's well-represented in CPAN, you have the advantage of having a lot of your work already done by experts.

So, as usual in questions like this, it depends on tastes and specifics.


All times are GMT -5. The time now is 08:35 AM.