Live data from Hacker News

Python consumes 38x more energy than Java

stratoflow.com

131–140 of 142 posts

Re: Python consumes 38x more energy than Java

#131

Earlier quoted context omitted.

The banking system.

I thought banks used COBOL?

> I thought banks used COBOL?

Banks have all kinds of random legacy crap written in all kinds of random languages. While COBOL is a lot more common, I guarantee you there are plenty of banks with bits of Fortran in their code bases. It is particularly found in older code for economic modelling, etc

Back in the old days, a lot of apps were written in Fortran that would never be written in that today. I used to work for a university where the application used to determine whether a student had met the graduation requirements for their degree was written in Fortran. Why Fortran? It was a manual process, then one of the professors offered to automate it for them, and he wrote the app in Fortran, because that was the language he was most comfortable with. And 30 years later they were still running it (although they finally replaced it with a COTS package when I worked there)

I once worked with an insurance company for whom a key business application was written in Turbo Pascal for DOS. They wrote it back in the 1980s when everyone had DOS machines. By the 2010s they were still running it in a VM. For all I know they are still doing that today

Re: Python consumes 38x more energy than Java

#132
post #87

Earlier quoted context omitted.

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-t…

I don’t think there is much point to these discussions without at least fixing some parameters/problem domain across languages. Of course pointer chasing is worse than a well-thought out encoding that fits many objects into a cache-line and is sequentially accessed. The question is — can the problem at hand use such a structure in the first place? Because not every problem can be solved with ECSs and the like - hell,…

I agree with most things you say. This is why most DBs are written in C relatives or descendants: C++, Rust, or just good old C. And Java dominates in the server-side business logic domain.

But boy it's cumbersome in anything other than those long running jit-friendly server-side processes..!

PS for IO-heavy purposes almost any mem-managed language would do. The real code running there is OS figuring out hardware and physical reality.

Re: Python consumes 38x more energy than Java

#133

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…

I would add that proof of work algorithms (Bitcoin type) where the goal is to endlessly compute hashes with no real computational productivity gain are the real offenders, regardless of which language they're written in.

>regardless of which language they're written in.

And given that a major limitation of bitcoin-hashing is the cost of electricity, I would guess that they're written in a very energy-efficient language already.

Re: Python consumes 38x more energy than Java

#134
post #103

Earlier quoted context omitted.

Considering energy costs money, our economic system is literally designed to reward lower energy consumption.

Strange, and yet we keep using more energy every year. Fun fact, we burn as much wood for heating as we did 100 years ago. What ends up happening is we consume all available energy. Economic growth is limited by energy so the whole system is incentivized to GROW energy usage, not reduce it. I suspect you are talking about per capita energy usage. Per capita energy usage has stayed around 80 mWh per person since 1965…

>Fun fact, we burn as much wood for heating as we did 100 years ago. What ends up happening is we consume all available energy. Economic growth is limited by energy so the whole system is incentivized to GROW energy usage, not reduce it.

That's because the population has increased but poverty hasn't substantially decreased, and the poorest people on the planet tend to burn wood for heating instead of using electricity.

Re: Python consumes 38x more energy than Java

#135
post #124
post #118

I can see C having 1.00 in table 4 in the article. But how does Python get 71.90 and JavaScript 4.45 ? Something seems off there.

JS has a JIT compiler, so for long running programs it can very well execute native machine code in the exact same way as C (plus a GC occasionally meddling with things). Also, it’s not even a bad JIT compiler, huge amount of development went into making it good. Standard Python is interpreted all the time, going from instruction to instruction giving a layer of abstraction that never disappears.

I agree a JIT works well for long running programs, but is that the situation we have here with these tests?

Re: Python consumes 38x more energy than Java

#136
post #129
post #128

Earlier quoted context omitted.

> Here is table 4 by geomean Table 4 has 3 columns. I can only guess that is the Energy column because the numbers don't match the calculation I made for the Time column. Pity about https.

I confused the tables, sorry. The first list considers the time values of "Table 3" in the 2021 paper, i.e. the three CLBG algorithms. The second list considers the time values of "Table 10" and "Table 11" in the 2021 paper, i.e. the four + five Rosetta algorithms. I also just noticed that meanwhile they unfortunately removed the tables from the online version of the referenced paper. It's a few years ago since I loo…

I'm now thoroughly confused but it's of no importance.

fwiw https://haslab.github.io/SAFER/scp21.pdf seems to have tables.

Re: Python consumes 38x more energy than Java

#137
post #130
post #125

Earlier quoted context omitted.

Yes, the link grabbing seo claims the benchmarks game has something to say about Java and energy-efficient — in fact the benchmarks game does not measure energy use. No, the link grabbing seo provides the correct source for Table 4 — "Source: Energy Efficiency across Programming Languages, SLE’17" — and google finds the article: https://greenlab.di.uminho.pt/wp-content/uploads/2017/09/pap... > looks the same Please l…

Yeah so the 12x gap in regex-redux is measuring the speed of two completely different libraries, and obviously boost is what’s slow. It’s not a language difference, nor even primarily an issue with means vs medians. The issue with regex-redux is slightly more of comparing apples to oranges. I assume you’re referring to regex-redux, but I was confused for a minute there because you linked directly to the C++ code for…

> … not … primarily an issue with means vs medians

We're comparing averages, why would we bother so much about the cause of an outlier.

> you linked directly to the C++ code for spectral-norm

You had linked to the wrong C and C++ code for spectral-norm, I linked to the code that was actually used.

> The time ratio of the Benchmarks Game fastest C version to the slowest C++ version is over 16x.

Again, you seem to be looking at the wrong repo.

The authors of "Energy Efficiency across Programming Languages, SLE’17" provided this repo —

https://sites.google.com/view/energy-efficiency-languages

https://github.com/greensoftwarelab/Energy-Languages

Re: Python consumes 38x more energy than Java

#138
post #95

Earlier quoted context omitted.

> Please explain how "AbstractProviderFactoryProxy" is related to the language. The language Java did, until some time ago, not allow you to pass functions as arguments. You had to make an anonymous inner class for example, satisfying some interface. Many design patterns are very much oriented towards a language like Java, which does/did not allow for higher order functions. Take the visitor pattern for example. It w…

You are misunderstanding the Visitor design pattern. It is not replaced by higher order functions — the point of it is to emulate multiple dispatch (over the usual single dispatch most languages have), that is, to change method implementation based not only on the receiver, but the argument as well. (It is replaced/has an exact analog with pattern matching though. Thankfully, Java has that available nowadays as well)…

Well, according to the wikipedia quote (https://en.wikipedia.org/wiki/Visitor_pattern#Definition) of GoF:

> Represent[ing] an operation to be performed on elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.

And that is exactly what you can do with higher order functions (or maybe procedures, if your visitor involves a side-effect). Instead of passing a "Visitor" object/instance, you pass in a "visitor" function/procedure. It too can achieve the goal of enabling to implement "a new operation" outside of "the class" (or whatever one uses instead of a class). "Operation" probably also being conceptually closer to function than object, since an operation is about "doing something", while an object is not necessarily actively doing something other than live.

By writing a function that accepts a function as an argument, you leave open the possibility for some other part of the code to define that function (a new operation). If you need to add another operation, you just define a new function. That you can pass in as an argument.

Re: Python consumes 38x more energy than Java

#139
post #94

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…

How is a class that holds a static method/function any different to simply namespacing? Never understood people’s problem with that. For example, what’s the problem with Java’s Math “class”? It only has stateless math functions like any other language, nothing is forced on you.

It does not have to be a problem in terms of it working or not.

The problem is rather, that a class comes with loads of conceptual baggage. It is conceptually not fit for the purpose of merely namespacing.

A good language will have a concept fit for the purpose of namespacing. Either something directly called "namespace" or something that is meant to namespace things, like modules. A class is rather for grouping methods that interact with the state of the objects.

Of course, if you don't have anything else available, you gotta take what you have. It will not serve making the code more readable though, as a potentially new reader of the code will expect a class to be instanced somewhere, as is typical for classes. It can lead to confusion. If there was however a concept "namespace", they will immediately know that it is for grouping a category of things.

Re: Python consumes 38x more energy than Java

#140
post #137
post #130

Earlier quoted context omitted.

Yeah so the 12x gap in regex-redux is measuring the speed of two completely different libraries, and obviously boost is what’s slow. It’s not a language difference, nor even primarily an issue with means vs medians. The issue with regex-redux is slightly more of comparing apples to oranges. I assume you’re referring to regex-redux, but I was confused for a minute there because you linked directly to the C++ code for…

> … not … primarily an issue with means vs medians We're comparing averages, why would we bother so much about the cause of an outlier. > you linked directly to the C++ code for spectral-norm You had linked to the wrong C and C++ code for spectral-norm, I linked to the code that was actually used. > The time ratio of the Benchmarks Game fastest C version to the slowest C++ version is over 16x. Again, you seem to be l…

I was talking about the Benchmarks game repo code. (But it doesn’t even matter because the SLE is equally bad.) And I was not comparing any averages, I was pointing out that use of boost is the entire reason the average is skewed and misleading. You seem to be misunderstanding my comments.
Post reply on HN