Re: Performance java vs. python

Discussion in 'Python' started by Daniel Fetchinson, May 19, 2009.

  1. >> >> On the one hand, there are developers who love big IDEs with lots of
    >> >> features (code generation, error checking, etc.), and rely on them to
    >> >> provide the high level of support needed to be reasonably productive
    >> >> in heavy-weight languages (e.g. Java).
    >> >>
    >> >> On the other hand there are developers who much prefer to keep things
    >> >> light-weight and simple. They like clean high-level languages (e.g.
    >> >> Python) which are compact enough that you can keep the whole language
    >> >> in your head, and require only a good text editor to be used
    >> >> effectively.
    >> >
    >> >This distinction is IMHO not correct. If you took a look at Java, you

    >> would
    >> >notice that the core language syntax is much simpler than Python's.

    >>
    >> That's half-true. The problem is that you have to digest a much bigger
    >> chunk of Java before you can start being productive. Consider how simple
    >> it is to write a non-regex grep in Python. In addition, Python's object
    >> model is simpler than Java's, not even talking about the contortions that
    >> Java's static class model forces you into.

    >
    >
    > I am new to Python. I am slowly realizing that Python might be a better
    > choice when compared to java on the server side. Is there any performance
    > comparison between Java and Python ? For example, if I use the J2EE solution
    > vs. python (Django etc.) on the server side, would one perform better over
    > the other ?


    Benchmarks always test for a given feature. The available benchmarks
    will most likely not test the feature relevant for your particular
    application simply because there are about a gazillion different ways
    of using a web framework. So the best you can do is simply test the
    bottleneck part of your application and see for yourself, otherwise
    you will be left with comments like "django is used at work because
    it's faster for us" or "I use j2ee because performance is better for
    my web app". When it will come to choosing your framework these will
    help little to none.

    Cheers,
    Daniel

    --
    Psss, psss, put it down! - http://www.cafepress.com/putitdown
    Daniel Fetchinson, May 19, 2009
    #1
    1. Advertising

  2. Daniel Fetchinson

    CTO Guest

    > Ah! I should have been careful before asking such "general" question about performance. I agree with you. But mine was more academic. I should not given a specific example.
    >
    > AFAIK, for java on the client side, JVM performance is one of the critical things which has been tuned to death until now. Even Google's Android which uses Java for the programming
    > language uses a Dalvik Virtual machine which was spefically designed to handle low CPU, memory and power environments. Similarly, Python can also be used to program on Nokia phones etc. > Of course programming natively (C/C++) would make a difference in environments where CPU, memory and power are a big constraint. Given the context, do we know how Python compares with
    > Java or even native programming. What is the overhead of Python's interpreted code ? Some standard benchmarks would help compare apples to apples though it may not help deciding which > framework to choose.
    >
    > -mohan


    Danger, will robinson- the dalvik jvm has precisely nothing to do with
    standard
    java. It uses the same syntax but otherwise operates entirely
    differently. Don't
    assume you'll get the same performance characteristics out of the
    other common
    jvm's.

    Geremy Condra
    CTO, May 19, 2009
    #2
    1. Advertising

  3. Daniel Fetchinson

    David Stanek Guest

    On Tue, May 19, 2009 at 5:43 PM, namekuseijin <> wrote:
    > someone said:
    >>>>>
    >>>>> If you took a look at Java, you would
    >>>>> notice that the core language syntax is much simpler than Python's.

    >
    > thanks for the laughs whoever you are!
    >


    I'm no Java fan, but I do agree that the core language is a bit easier
    for people to grasp. I have also heard that from other developers as
    well.

    --
    David
    blog: http://www.traceback.org
    twitter: http://twitter.com/dstanek
    David Stanek, May 19, 2009
    #3
  4. Daniel Fetchinson

    Chris Rebert Guest

    On Tue, May 19, 2009 at 3:21 PM, David Stanek <> wrote:
    > On Tue, May 19, 2009 at 5:43 PM, namekuseijin <> wrote:
    >> someone said:
    >>>>>>
    >>>>>> If you took a look at Java, you would
    >>>>>> notice that the core language syntax is much simpler than Python's.

    >>
    >> thanks for the laughs whoever you are!
    >>

    >
    > I'm no Java fan, but I do agree that the core language is a bit easier
    > for people to grasp. I have also heard that from other developers as
    > well.


    Perhaps for those with a C/C++ background, but I doubt that's true
    generally speaking.

    Cheers,
    Chris
    --
    http://blog.rebertia.com
    Chris Rebert, May 19, 2009
    #4
  5. Daniel Fetchinson

    namekuseijin Guest

    On Tue, May 19, 2009 at 7:21 PM, David Stanek <> wrote:
    > On Tue, May 19, 2009 at 5:43 PM, namekuseijin <> wrote:
    >> someone said:
    >>>>>>
    >>>>>> If you took a look at Java, you would
    >>>>>> notice that the core language syntax is much simpler than Python's.

    >>
    >> thanks for the laughs whoever you are!
    >>

    >
    > I'm no Java fan, but I do agree that the core language is a bit easier
    > for people to grasp. I have also heard that from other developers as
    > well.


    Really? Core language, eh?

    Just take a look at just the summary of the Java language spec:
    http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html

    Then compare with the summary for Python 3.0 language reference:
    http://docs.python.org/3.0/reference/

    Like comparing a mammoth to a zebra.

    Besides, how is:
    for( int i=0; i<10; i++ )

    simpler than:
    for i in (range(10))

    ?

    Scripting languages like Python eventually led Java to provide a more
    friendly for, which they call, quite appropriately, enhacedFor.
    Here's it in action:
    for (Map.Entry<String, Integer> e : histogram.entrySet())

    in Python:
    for e in histogram.items()

    fun.

    Here's a more complete example, available a bit down from:
    http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.14.2

    Map<String, Integer> histogram = ...;
    double total = 0;
    for (int i : histogram.values())
    total += i;
    for (Map.Entry<String, Integer> e : histogram.entrySet())
    System.out.println(e.getKey() + " " + e.getValue() / total);

    in Python:
    histogram = ...
    total=0
    for i in histogram.values(): total+=i
    for e in histogram.items():
    print( e[0] + " " + str( e[1]/float(total) ))

    yeah, surely a friggin' lot more complex... and we didn't even come to
    use any of Java's HUUUGE APIs, just the core lang... BTW, I'm amused
    that Java's string concatanating doesn't require an explicit cast from
    the float result.

    anyway, again, thanks for the laughs.
    namekuseijin, May 20, 2009
    #5
  6. Daniel Fetchinson

    Ant Guest

    On May 20, 6:46 pm, namekuseijin <> wrote:
    > anyway, again, thanks for the laughs.


    I'm a Java developer in my day job, and I use Jython for testing out
    ideas and prototyping, due to the way Jython makes writing Java so
    much easier... Those examples were spot on - things weren't much
    simpler before generics, as you had casting going on everywhere. Not
    to mention the nice primitive / object divide to add to the languages
    complexity.

    And the libraries in Java... Compare cat implementations:

    # Python
    fh = open("myfile.txt")

    for line in fh:
    print line

    // Java

    ....

    BufferedReader reader = new BufferedReader(new FileReader
    ("myfile.txt"));
    String line = reader.readLine();
    while (line != null) {
    System.out.println(line);
    }

    ....

    And that's without all of the class/main method boilerplate or try
    catch block required due to checked exceptions.

    I've taught both Java and Python, and the latter is far easier to pick
    up and run with, from both a syntactic point of view and in the use of
    the libraries.
    Ant, May 20, 2009
    #6
  7. Daniel Fetchinson

    Aahz Guest

    In article <gv1nor$10uu$>,
    namekuseijin <> wrote:
    >
    >I find it completely unimaginable that people would even think
    >suggesting the idea that Java is simpler. It's one of the most stupidly
    >verbose and cranky languages out there, to the point you can't really do
    >anything of relevance without an IDE automatically pumping out lots of
    >scaffold code for you.


    Well, I wouldn't go quite that far; after all, I managed to integrate
    BouncyCastle into a Java app without an IDE (or really knowing Java, for
    that matter). But you have a valid point once the excessive generalizing
    is removed. ;-)
    --
    Aahz () <*> http://www.pythoncraft.com/

    "A foolish consistency is the hobgoblin of little minds, adored by little
    statesmen and philosophers and divines." --Ralph Waldo Emerson
    Aahz, May 20, 2009
    #7
  8. Duncan Booth <> wrote:
    >namekuseijin <> wrote:
    >> I find it completely unimaginable that people would even think
    >> suggesting the idea that Java is simpler. It's one of the most stupidly
    >> verbose and cranky languages out there, to the point you can't really do
    >> anything of relevance without an IDE automatically pumping out lots of
    >> scaffold code for you.

    >But that means Java programmers are obviously more productive than Python
    >programmers: they produce many more lines of code per day even if much of
    >it is boileplate or even automatically generated. Managers like that.
    >
    >OTOH, I consider it a productive day if I end up with fewer lines of code
    >than I started with.


    A friend once justified a negative LOC count as being the sign of a
    good day with the following observation:

    Code that doesn't exist contains no bugs.
    Code that doesn't exist takes no time to execute.
    Code that doesn't exist takes up no space.
    Code that doesn't exist doesn't need maintenance.

    Once, when faced with a rather hairy problem that client requirements
    dictated a pure Java solution for, I coded up a fully functional
    prototype in Python to get the logic sorted out, and then translated
    it. Even given the optimisations of manual translation, and being
    able to dispose of one portion of the Python which Java supplied the
    functionality for out of the box (thread timeout, I think it was),
    the code grew by 200%. That was a very unproductive day.

    --
    \S

    under construction
    Sion Arrowsmith, May 21, 2009
    #8
  9. Daniel Fetchinson

    Lie Ryan Guest

    Sion Arrowsmith wrote:
    >> OTOH, I consider it a productive day if I end up with fewer lines of code
    >> than I started with.

    >
    > A friend once justified a negative LOC count as being the sign of a
    > good day with the following observation:
    >
    > Code that doesn't exist contains no bugs.
    > Code that doesn't exist takes no time to execute.
    > Code that doesn't exist takes up no space.
    > Code that doesn't exist doesn't need maintenance.


    Why not call a day productive when the UnitTest that passed has
    increased or stayed constant with reduced LOC.

    > Once, when faced with a rather hairy problem that client requirements
    > dictated a pure Java solution for, I coded up a fully functional
    > prototype in Python to get the logic sorted out, and then translated
    > it. Even given the optimisations of manual translation, and being
    > able to dispose of one portion of the Python which Java supplied the
    > functionality for out of the box (thread timeout, I think it was),
    > the code grew by 200%. That was a very unproductive day.


    Jython ?
    Lie Ryan, May 21, 2009
    #9
  10. Lie Ryan <> wrote:
    >Sion Arrowsmith wrote:
    >> Once, when faced with a rather hairy problem that client requirements
    >> dictated a pure Java solution for, I coded up a fully functional
    >> prototype in Python to get the logic sorted out, and then translated
    >> it. [And it wasn't pleasant.]

    >
    >Jython ?


    This was back during Jython's wilderness years (barely maintained at
    2.1 while the rest of us were on 2.3, or something like that. Mind
    you, you could argue it's four versions behind at the moment.) Plus, I
    was the only Python-head in the company just then. Plus, I meant that
    "client requirements dictated a pure Java solution": they required the
    ability to do a code audit. It's amazing the number and variety of
    people who've drunk the Java Kool-Aid.

    --
    \S

    under construction
    Sion Arrowsmith, May 21, 2009
    #10
  11. Daniel Fetchinson

    namekuseijin Guest

    On May 21, 7:47 am, (Sion Arrowsmith) wrote:
    > Duncan Booth  <> wrote:
    >
    > >namekuseijin <> wrote:
    > >> I find it completely unimaginable that people would even think
    > >> suggesting the idea that Java is simpler.  It's one of the most stupidly
    > >> verbose and cranky languages out there, to the point you can't really do
    > >> anything of relevance without an IDE automatically pumping out lots of
    > >> scaffold code for you.

    > >But that means Java programmers are obviously more productive than Python
    > >programmers: they produce many more lines of code per day even if much of
    > >it is boileplate or even automatically generated. Managers like that.

    >
    > >OTOH, I consider it a productive day if I end up with fewer lines of code
    > >than I started with.

    >
    > A friend once justified a negative LOC count as being the sign of a
    > good day with the following observation:
    >
    > Code that doesn't exist contains no bugs.
    > Code that doesn't exist takes no time to execute.
    > Code that doesn't exist takes up no space.
    > Code that doesn't exist doesn't need maintenance.


    Amusing tales. And very true too -- managers just love LOC and
    straightjacket programming environments.

    Here's what the father of Unix, Ken Thompson, said once about LOC:
    "One of my most productive days was throwing away 1000 lines of code."

    http://www.brainyquote.com/quotes/quotes/k/kenthompso254858.html
    namekuseijin, May 21, 2009
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jm
    Replies:
    1
    Views:
    507
    alien2_51
    Dec 12, 2003
  2. Robert Brewer
    Replies:
    1
    Views:
    343
    Dave Benjamin
    Jan 10, 2004
  3. Bill
    Replies:
    14
    Views:
    799
    Fulvio
    Mar 23, 2006
  4. reinsn
    Replies:
    1
    Views:
    383
    Diez B. Roggisch
    May 19, 2006
  5. Software Engineer
    Replies:
    0
    Views:
    324
    Software Engineer
    Jun 10, 2011
Loading...

Share This Page