EDIT: fwiw, classic Fortran is twice as fast as java :P As is Rust, but that's less funny to me
They also seemed to have avoided libraries like numpy.
In my mind, python made it possible to hardware optimize with libraries like numpy quite easily. Avoiding it is a mistake. I'll try to see if I have time to play the game myself and throw my attempt in there.
EDIT: seems to be https://chapel-lang.org/
I think most of the people who "crap on" Fortran, when they say "Fortran", mean FORTRAN 77, not Fortran 2018
only clueless people looking for clout online!
I severely doubt anything I do touches fortran millions times a day unless it's google search that runs on it.
"Source: Energy Efficiency across Programming Languages, SLE’17"
and google finds —
https://greenlab.di.uminho.pt/wp-content/uploads/2017/09/pap...
Well optimized Java is very lean and can be incredibly performant, but the median modern Java app is an obese cronenberg made out of gigabytes of SpringBoot dependencies. That's not particularly fast; and well optimized python will run circles around it.
From my personal experience: benchmarks showed Jruby was MUCH MUCH faster the 'normal' Cruby. But try running a basic rails application on jruby and it's 10-100x slower, even after minutes of repeating the same request.
(disclaimer, this was a few years back and purely anecdotal)
A spring boot app will generally be very performant. It will indeed use more memory though.
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.
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.
These takes fail to take into account the huge discrepancy between the market value produces by computer systems per unit of energy. It is such a huge value that it barely matters compared to most other industries, plus the net amounts are not particularly high either. Nonetheless, it can matter in certain cases, and Java is a great choice for server setups due to its GC being very efficient in doing only the necessary amount of work.
Also, I’m not convinced that a full on complex assembly app would be leaner than the same program written in a lower level language. That’s an area where compilers are very good, and humans only have so much working memory/hair on their head to hand-optimize whole programs.
Most of the implementations for LLMs runtimes I know of are Python using PyTorch. I believe most of the heavy lifting is written in C++ (llama.cpp), though.
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.
Correlation or causation?
My intuition states that this isn't the case, but intuition can be wrong.
Using VScode with the Sqlx package I get compile time errors on my SQL - as a result I haven't ran a binary with a typo from my SQL in the last 12 months.
It will require you to write more correct code, so the end product is more likely to come out better. But it is not easy, even for building "good" software. (Assumption: "good" := correct, maintainable, efficient, and robust -- Rust nails the efficient part.)
The deployment and consumption of said code matters a lot for that.
Here is the source of the table: https://greenlab.di.uminho.pt/wp-content/uploads/2017/10/sle...
So in reality there are very few places where you would want to use Go over modern C#.
PDF: https://repositorio.inesctec.pt/bitstream/123456789/5492/1/P...
The human mental energy required for programming, unfortunately, has not been measured. ;-)
It probably does not balance the 38x, and probably the JIT optimizes parts of it away, but surely the cost is far from zero.
Also what about the computational resources it takes to just run a JVM, compared to running a Python program?
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.
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 will get you a "Visitor" in your class name implementing a visitor. How would it work in other languages, which provide higher order functions or always did so? Well, you would simply write a function and depending on whether your language has static types, annotate its types for arguments and return value. You would then pass this function in as an argument, whose name can be "visitor".
Take a factory pattern as an example. How would it work? Well, a factory can be expressed using a function, that returns another function. It takes the arguments, that specify/narrow down how the returned function works. In Java it would become a Factory class instead. Instead of using a simple function, one needs (needed?) to build a whole class around that, because one could not return a function. So one would build that class and then make it return an object instead, which of course again must be derived from some class ...
Just 2 examples that quickly come to mind.
> 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.
It is certainly true, that people also write shit code in Python. I have seen very popular libraries, which wrap REST APIs in objects. It is silly, because objects are meant to have some lifetime in which they communicate with each other and possibly change their state. There is no changing state though. Everything is a response from the REST API, which by the definition of REST should transfer the representative state in its responses. I don't want any in between stored state. I want the state that the API gives me. It is very much a more functional view on things. But Python programmers will go "make classes!" nevertheless. Because noun. Because not thinking about whether they really need a class. Because thinking that one approach fits it all and the only approaches they learned were procedural at the beginning of their learning and then OOP, which is complex enough to take years to learn properly, so that is where they stopped.
However, Python always (for a very long time?) has allowed you to pass procedures as arguments and as such does not encourage "AbstractProviderFactoryProxy" as much as Java does. Still, sometimes former Java developers try their hand at some Python code ...
> If you are writing modern Java syntax, there is little that is more stable and readable than good modern Java syntax.
Modern Java certainly has improved. But there is a lot of relearning to be done for those generations of Java programmers, to get rid of the "every noun a class" mentality.
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.
Even when what you Utils.see Utils.is a verb, you Utils.must still Utils.jump to Utils.make a class.
Java 5's static imports at least allow cleaning up the call site, although the documentation advises (in bold) using this feature "very sparingly".
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<50: x=x+1
print (x)
Runs 5 times slower here than the same in PHP: $x=0;
for ($i=0; $i<10e6; $i++)
if ($i<50) $x++;
echo "$x\n";
Tested with: time python3 loop.py
Which gives me 0.31sAnd:
time php loop.php
Which gives me 0.06sA factor of five seems to be roughly the average when comparing Python to PHP for a bunch of different code constructs I tried.
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.
> it won’t be idiomatic
I just looked at the first example:
C: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
C++: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
The C++ doesn’t use shared_ptr or STL or anything, and isn’t that far from the C code, but it isn’t that close either. I wonder if it’s OMP configuration that’s causing it to be slower, or maybe just instruction cache or something since the C++ is larger.
The results say this one has C++ going 50% slower. I’m a little skeptical it’s the compiler’s or the language’s fault. I’d speculate it might have more to do with how the program is written.
But how does Python get 71.90 and JavaScript 4.45 ?
Something seems off there.
Standard Python is interpreted all the time, going from instruction to instruction giving a layer of abstraction that never disappears.
6.52 arithmetic average more than the 10 selected C programs.
Seems off because?