You are not logged in.

#1 2005-08-18 00:44:34

arooaroo
Member
From: London, UK
Registered: 2005-01-13
Posts: 1,268
Website

Python vs Java - simple benchmark comparison

Hi all,

I recently posted a speed comparison of Python vs Java.

Following Xentac's suggestion, I imported Psyco to see if I could get any JIT benefits in the Python scripts. I then tried the latested Java JDK6 dev binaries too. This follow-up can be found here.

Please be aware that I'm totally aware of the vast limitations of micro-benchmarks like these. Still, although they are based on someone else's code, I like them because they represent the typical tasks I often carry out in both my Python and Java programming: IO, lists, hashes, for loops, etc.

Any comments welcome, especially on how to optimise the Python code. I can already see a couple of ways that ought to improve the Java tests.

Offline

#2 2005-08-18 01:47:06

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: Python vs Java - simple benchmark comparison


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#3 2005-08-18 11:38:39

arooaroo
Member
From: London, UK
Registered: 2005-01-13
Posts: 1,268
Website

Re: Python vs Java - simple benchmark comparison

Ah, I forgot about this site - 'tis well cool.

So, this also confirms that Java is lighter on the CPU. However, this also highlights the obvious that Java takes up more memory (I'd say an average of 5% more).

Did anyone notice how the table of results is a bit odd. They talk about values < 1, but there no negative numbers. My assumption is that the values with the shading behind represent -ve numbers.

Offline

#4 2005-08-18 14:49:09

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: Python vs Java - simple benchmark comparison

Relative performance: values > 1 mean the Java program used more than the Python program; values < 1 mean the Java program used less than the Python program.

yeah. it seems the range from 0 to 1 is somehow caculated differently than from 1 to infinity. I don't get it either i guess.
I find the bar graph useful, and the win/loss table at the bottom very interesting.

my poor ruby is a bit slow it seems. Oh well, I guess there is a small price to pay for elegance in the language. Hopefully it will get better in coming versions.


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#5 2005-08-19 19:22:09

xerxes2
Member
From: Malmoe, Sweden
Registered: 2004-04-23
Posts: 1,249
Website

Re: Python vs Java - simple benchmark comparison

i've tried both psyco and pyrex,

about psyco i didn't notice any speed improvements at all, i think you must fix the code somehow to fit psyco better,

and pyrex compiles python and pyrex code (pyrex code is modified python code with c declared functions and statically declared variables) down to python c code which you compile with gcc, so fully optimized pyrex runs with c speed so that's not a fair comparison to just pure java, in that case you should compare it to native java(gcj?),

and about the benchmarks, well, the differences are probably so small that it doesn't matter in most cases, i'm not using java myself but complaints I hear from other people usually are about startup/respons times and memory consumption and not about the actual running of the app so i don't think aroos figures are wrong at all which also that other sites benchmarks showed, weren't java a tad faster there also?


arch + gentoo + initng + python = enlisy

Offline

#6 2005-08-19 19:33:41

arooaroo
Member
From: London, UK
Registered: 2005-01-13
Posts: 1,268
Website

Re: Python vs Java - simple benchmark comparison

I agree. I honestly am not trying to say that Java is better and Python is rubbish. I love em both. There's not a great deal of difference for the most part.

I just felt that people assumed that Java was slow because they've heard it's slow, or had prior experience of the old versions.

I have friend's saying "ugh, Java is sloowwww." And so avoid it. Yet, these same people rave about Perl and Python apps. My point was simply, hate Java for other reasons - not speed!

You may notice that the Java executable is only 63K. The bulk of Java comes from its extensive class library that ships with the runtime. People think that Java must load up all the classes or something before running, when in fact it only ever loads with it needs. So, whilst the package itself is large, any sure, it does require more memory than other languages, I just don't believe it's as bulky as some assume.

The motivation for those benchmarks was a comment on Frugalware's IRC channel where someone tried it out, said it was slow, removed it, and preferred the Python/gtk front-end they have instead. Followed with some insightful remark that Java only for web apps! I don't mind others prefering other front-ends. But is Jacman really slow? Please tell me, because it runs like a dream on my system. It would go even quicker if with pacman-optimize.

Offline

#7 2005-08-19 19:37:27

cmp
Member
Registered: 2005-01-03
Posts: 350

Re: Python vs Java - simple benchmark comparison

xerxes2 wrote:

i've tried both psyco and pyrex,

about psyco i didn't notice any speed improvements at all, i think you must fix the code somehow to fit psyco better,

I have written a simple game and hat +40 frames when using psyco, so I guess there is a speed difference.

Offline

#8 2005-08-20 17:33:09

xerxes2
Member
From: Malmoe, Sweden
Registered: 2004-04-23
Posts: 1,249
Website

Re: Python vs Java - simple benchmark comparison

do you mean 40 frames more with psyco?
well, maybe you've found out how it really works,

aroo wrote:

I have friend's saying "ugh, Java is sloowwww." And so avoid it. Yet, these same people rave about Perl and Python apps. My point was simply, hate Java for other reasons - not speed!

are there any big pure python/pygtk apps out there really?
someone should write an exact clone of azureus in python/pygtk and compare them side by side irl use,


arch + gentoo + initng + python = enlisy

Offline

#9 2005-08-20 17:43:25

cmp
Member
Registered: 2005-01-03
Posts: 350

Re: Python vs Java - simple benchmark comparison

yes, 40 frames more with psyco, I used it like this:

if options.jit_compile:
        try:
                import psyco
                psyco.log()
                
                if options.jit_method == 'profile':
                        psyco.profile()
                elif options.jit_method == 'full':
                        psyco.full()
        except ImportError, err:
                print "::warning no psyco jit-compilation available. %s" % err

Offline

#10 2005-08-20 19:00:45

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: Python vs Java - simple benchmark comparison

arooaroo wrote:

My point was simply, hate Java for other reasons - not speed!

Syntax!!

Offline

#11 2005-08-21 02:25:45

Euphoric Nightmare
Member
From: Kentucky
Registered: 2005-05-02
Posts: 283

Re: Python vs Java - simple benchmark comparison

Dusty wrote:
arooaroo wrote:

My point was simply, hate Java for other reasons - not speed!

Syntax!!

I see your point, but I laughed out loud when i saw that response...and now everyone is looking at me weird (at work of course)...I was sort of thinking the same thing.

Offline

#12 2005-08-21 09:43:14

arooaroo
Member
From: London, UK
Registered: 2005-01-13
Posts: 1,268
Website

Re: Python vs Java - simple benchmark comparison

Dusty wrote:
arooaroo wrote:

My point was simply, hate Java for other reasons - not speed!

Syntax!!

lol. Indeed - it's getting uglier, that's for sure.

Of course, if I was using a Java app, then syntax wouldn't be an issue. tongue

Offline

#13 2005-08-21 12:50:53

soniX
Member
From: Oslo, Norway
Registered: 2004-01-23
Posts: 161

Re: Python vs Java - simple benchmark comparison

what exactly is wrong with the Java syntax ?

Offline

#14 2005-08-21 20:13:37

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: Python vs Java - simple benchmark comparison

I love Java syntax... only I hate it too...

Offline

#15 2005-08-21 20:16:15

wdemoss
Member
From: WV - USA
Registered: 2004-01-18
Posts: 222

Re: Python vs Java - simple benchmark comparison

Dusty wrote:

I love Java syntax... only I hate it too...

I think i've thought this about every language I've used (well, except maybe perl wink.


Hobbes : Shouldn't we read the instructions?
Calvin : Do I look like a sissy?

Offline

#16 2005-08-22 01:56:46

Euphoric Nightmare
Member
From: Kentucky
Registered: 2005-05-02
Posts: 283

Re: Python vs Java - simple benchmark comparison

Dusty wrote:

I love Java syntax... only I hate it too...

So are you officially a java hater now? 

I mean, do you ever use java anymore?

Offline

#17 2005-08-22 06:15:13

arooaroo
Member
From: London, UK
Registered: 2005-01-13
Posts: 1,268
Website

Re: Python vs Java - simple benchmark comparison

Euphoric Nightmare wrote:

So are you officially a java hater now? 

I mean, do you ever use java anymore?

I take it you didn't see Dusty's Sick of Java thread then?!

Offline

#18 2005-08-22 21:39:43

Euphoric Nightmare
Member
From: Kentucky
Registered: 2005-05-02
Posts: 283

Re: Python vs Java - simple benchmark comparison

arooaroo wrote:
Euphoric Nightmare wrote:

So are you officially a java hater now? 

I mean, do you ever use java anymore?

I take it you didn't see Dusty's Sick of Java thread then?!

No...I saw it.  I didn't know if he was going to stop using it 100% or not.  I had heard that he was redoing ensmer in python as well...I'm just curious mainly i guess.

Offline

#19 2005-08-22 21:55:21

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: Python vs Java - simple benchmark comparison

Euphoric Nightmare wrote:

So are you officially a java hater now?

No. I don't really hate any languages, except SQL and Basic, but they're so bad, I don't really think they even qualify as languages.

I mean, do you ever use java anymore?

Since I wrote the sick of Java thread, I have done approximately no programming whatsoever, so its hard to answer that.

Dusty

Offline

#20 2005-08-23 04:13:08

Euphoric Nightmare
Member
From: Kentucky
Registered: 2005-05-02
Posts: 283

Re: Python vs Java - simple benchmark comparison

interesting...

yeah...SQL and basic do suck...good point

Offline

#21 2005-08-24 04:32:48

sweiss
Member
Registered: 2004-02-16
Posts: 635

Re: Python vs Java - simple benchmark comparison

I think it makes sense that Java is faster, as you have to declare your variables, for example, while Python has to figure it out itself.

Different languages for different goals, I guess.

Offline

#22 2005-08-27 10:03:27

Riklaunim
Member
Registered: 2005-04-09
Posts: 106
Website

Re: Python vs Java - simple benchmark comparison

Something interesting... http://www.flat222.org/mac/bench/ smile

Offline

#23 2005-08-27 14:05:34

arooaroo
Member
From: London, UK
Registered: 2005-01-13
Posts: 1,268
Website

Re: Python vs Java - simple benchmark comparison

Just confirms what I said with regards to Java vs Python.

Of course, if you were to benchmark the time it takes to write an algorithm for task X in Java and Python, it would probably be the other way around!

Offline

Board footer

Powered by FluxBB