Live data from Hacker News

Python consumes 38x more energy than Java

stratoflow.com

41–50 of 142 posts

Re: Python consumes 38x more energy than Java

#42

Just write in Rust, it's easier to build good software than either of these languages (yea, yea, do you data analyst stuff in python until you start using POLARS). At this point it's a far superior ecosystem from a developer experience point of view and the fact it's going to get you as close to efficient as possible without you thinking too far into it is a welcome side effect. Using VScode with the Sqlx package I g…

Are there any good interactive programming options in Rust? That's the main draw of a dynamic language like Python for ad hoc data science tasks, the semantics just lines up well with the highly iterative nature of the work.

Re: Python consumes 38x more energy than Java

#43

While Java's compiler or JIT is probably one of the most optimized softwares in existence, how do we measure, what overhead the language nudges the programmers to build? I am thinking of AbstractProviderFactoryProxy and similar. Or that for a very long time it forced you (or still does to a degree) to put everything into classes, breeding 1 or 2 generations of programmers, who see a noun and jump to making a class an…

Please explain how "AbstractProviderFactoryProxy" is related to the language.

I have taken over as lead for a Python project and what I see all the Java problems people used to make fun of (none have worked in Java before) and worse. On top, everything has an interface starting with "I", C# style. Methods in entities, service classes are instantiated with state etc. And side-effects are all over the place.

If you are writing modern Java syntax, there is little that is more stable and readable than good modern Java syntax.

Re: Python consumes 38x more energy than Java

#44

Earlier quoted context omitted.

You seem to be conflating speed and memory usage. A spring boot app will generally be very performant. It will indeed use more memory though.

I did an excercise some time ago and managed to get two file transfer apps, one in Rust and one in Java, where the performance was effectively the same (in some cases with a slight Java edge!), but the memory consumption was orders of magnitude in favor of Rust. The JVM is a wonder of engineering, and Java is indeed quite fast.

Most reasonable people in the industry understand that Java can be fast, especially in benchmark-oriented code. The problem is that the OOP-first ideology of the language and the coding culture surrounding it is not performance-oriented, especially with modern machines that don't like pointer-chasing.

One not very well known fact is that just-in-time compilers have more optimisation-specific info than pure ahead-of-time compilers, i.e. most used code paths, real types used for polymorphic values, etc. That is, until your AOT compiler uses something like a profile-guided optimisation.

In practice though writing to performance in Java takes a very dedicated effort. Real Java programs are horrible with memory, okay (for an AOT languguage) in long-running compute-intensive tasks, and painfully slow at short-living tasks such as CLI utils.

Almost any real program written in C would run circles around most off-the-shelf Java programs.

Turns out, though, all of that doesn't really matter :-)

Re: Python consumes 38x more energy than Java

#45

C++ uses 34% more energy than C? I thought C code was generally also valid C++ code and so you really should be able to get the same performance and energy consumption. Very odd.

You can write C in C++ but it won't be idiomatic C++. I've seen plenty of experienced "C++" developers that have no idea what is "shared_ptr".

Re: Python consumes 38x more energy than Java

#46

Earlier quoted context omitted.

You seem to be conflating speed and memory usage. A spring boot app will generally be very performant. It will indeed use more memory though.

I did an excercise some time ago and managed to get two file transfer apps, one in Rust and one in Java, where the performance was effectively the same (in some cases with a slight Java edge!), but the memory consumption was orders of magnitude in favor of Rust. The JVM is a wonder of engineering, and Java is indeed quite fast.

Aren't file transfers done by the kernel via sys-calls?

All languages would be equally fast, given they don't do something stupid like reading and writing individual bytes.

Re: Python consumes 38x more energy than Java

#47
Is Python's "values don't change, they get replaced by new ones stored elsewhere" approach what makes it slow?

I would like to see some micro-benchmarks which pin down the bottlenecks.

For example, this minimal benchmark with one variable and a few control structures:

    x=0
    for i in range(int(10e6)):
        if i
Runs 5 times slower here than the same in PHP:

    $x=0;
    for ($i=0; $i
Tested with:

    time python3 loop.py
Which gives me 0.31s

And:

    time php loop.php
Which gives me 0.06s

A factor of five seems to be roughly the average when comparing Python to PHP for a bunch of different code constructs I tried.

Re: Python consumes 38x more energy than Java

#48
post #37

Earlier quoted context omitted.

Fortran is a beast. People crap on it all the time yet use it often millions of times a day without realizing it.

use in what ? I severely doubt anything I do touches fortran millions times a day unless it's google search that runs on it.

The banking system.

Re: Python consumes 38x more energy than Java

#49
Amazing. I have seen this list popping up in my LinkedIn feed for more than a year already and it keeps coming back.

While any benchmark is of course interesting when considered on its own, the conclusions that people draw from this list tend to be complete nonsense: "Python is bad for the environment", "we should switch to language xxx to combat global warming" etc.

First of all, especially for the slower languages in this list, it is extremely rare that application code written in that language is the bottleneck of a performance critical application. Typically the bottlenecks of every day applications tend to be databases and network. If you need heavy number crunching, there tend to be excellent libraries available written in lower level languages, such as e.g. for Python NumPy and Pandas. If you are really concerned about the energy footprint of your application, you're probably better off with optimizing these components. Or optimizing the higher level architecture of your own application, which tends to be a lot easier in a higher level langguage.

Second, coding in a faster language is often not economically possible. Programming the same application in C will normally take much longer than coding it in Python. Developing time costs money and can also mean loss of opportunity.

And finally, the 'greenest' language of them all was not even included in this list: assembly. I guess the author must have realized in the back of his head that such a difficult language wasn't a realistic option for switching to a more energy efficient solution. He/she just failed to realize that this argument applies to many other languages as well.

Re: Python consumes 38x more energy than Java

#50

Earlier quoted context omitted.

You seem to be conflating speed and memory usage. A spring boot app will generally be very performant. It will indeed use more memory though.

No man spring boot is hideously slow as well compared to vanilla java. It's pretty fast compared to many other things, but that's just because vanilla java is extremely fast. You often see like 15-30 second start times for springboot apps, which is hilarious and 13-28 seconds longer than it has any business taking.

Have you tried Spring native?
Post reply on HN