this post was submitted on 28 Oct 2023
107 points (95.7% liked)

Programmer Humor

32396 readers
507 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 

2020 study pdf.

After seeing this a couple years ago I started to be more responsible for my PHP code, writing it even with the slightest micro-optimizations possible, since more times people use my code (especially due to nature of PHP being executed in every http request), more energicity they waste because of my lazyness and more they pollute the planet. JIT was NOT included in this experiment, so the number can be much more lower.

I hope you will be responsible for your code so on too (generally I mean people using interpreted languages).

all 28 comments
sorted by: hot top controversial new old
[–] walthervonstolzing@lemmy.ml 34 points 1 year ago

OK, but are they taking into account the energy expenditure of the programmer's brain while writing the program? The amount of calories his/her brain has to burn in order to produce & debug the code?

[–] Skelectus@suppo.fi 16 points 1 year ago (1 children)

Why is there such a large jump from TS to JS?

[–] souperk@reddthat.com 10 points 1 year ago* (last edited 1 year ago)

good question, probably the transpiled code does not match the optimized js. Maybe, if they targeted the same js version as js version they are benchmarking, the results would be equivalent?

Also, if they are using a node version with ts support, it will compile the ts before execution which means they are measuring the impact of the compiler, which can be a lot for small snippets.

[–] mr47@kbin.social 14 points 1 year ago (3 children)

Quite a few unexpected results here...

  1. I'm surprised the C binary is not the smallest, and it's outdone by Pascal, of all languages.
  2. The speed/energy difference between Java and C# (almost a factor of 2 in favor of Java).
  3. The relatively good performance of JavaScript compared to other loosely typed multi-paradigm scripting languages.
  4. The difference between C# and F#. That's actually a good reason to question the accuracy of these tests and results.
[–] words_number@programming.dev 11 points 1 year ago* (last edited 1 year ago)

The JS one is not surprising at all. There's no other loosely typed multi-paradigm scripting language where such insane shitloads of money and developer time have been spent for optimizing its execution (by some of the largest tech companies). Kinda funny considering that the language design is complete horse shit.

Your 2nd point is really quite surprising. I also wouldn't have thought that java would beat Go in both energy and time by that margin!

[–] tamlyn@lemmy.zip 10 points 1 year ago (1 children)

Without any information how this test result got achieved. It's kind of useless. It's like to read the headline of a paper. So sure you should question the accuracy of this image. But i would agree it's fun to look at it

[–] DaTingGoBrrr@lemmy.ml 8 points 1 year ago (1 children)
[–] tamlyn@lemmy.zip 4 points 1 year ago* (last edited 1 year ago)

Maybe i was blind, haven't seen it. Thx, I look into it because i'm curious, but it's long, so need first some time for it

[–] sim642@lemm.ee 3 points 1 year ago (1 children)

Pascal is a simpler and more limited language, so it's not entirely surprising. It also has less and smaller standard libraries to link in.

As to C# and F#, what's wrong with the difference? The functional coding style of F# prefers immutable data over possibly mutable ones in C# and that requires more allocations and garbage collection.

[–] mr47@kbin.social 1 points 1 year ago

I haven't looked into the details of the actual code, but I would expect the compiler optimizations and JIT to figure it all out and end up with very similar native code. Especially since both languages are mature and had enough time to reach such goals. But it's quite possible my assumptions are incorrect.

[–] sim642@lemm.ee 12 points 1 year ago (1 children)

Or you could just write your backend in JS and save a lot according to this table.

The big inefficiency of PHP is that every request is handled in a new instance as opposed to one process running the server continuously.

[–] kovalensky@lemmygrad.ml 9 points 1 year ago* (last edited 1 year ago) (1 children)

That actually depends on the type of a server.

Common PHP-FPM for example allows for persistent PHP processes to handle multiple requests, reducing the overhead of creating a new instance for each request.

Also then there was no stable JIT while doing this study, so probably situation has changed a lot in a better way, but writing efficient code will always be a requirement.

[–] sim642@lemm.ee 1 points 1 year ago (1 children)

That allows processes to be reused but the interpreter must still be set up cleanly each time and torn down. That includes things like open files, database connections and application configurations.

[–] kovalensky@lemmygrad.ml 1 points 1 year ago* (last edited 1 year ago)

Yes, you are completely right, if your code writing style is basic, all of it being solved by your application design. Not sure for open files (in contrast with disk cache of most OS), we have configurable persistent db connections, app configurations in most cases being saved in some cache (PHPBB cache is an example). Most of the time the code you wrote is the main factor of your code speed and waste coefficient. Luckily every year we get more modern PHP interpreter, if we look back at PHP 5, it was a complete disaster in the terms of performance, but I don't say that it will be as resource-saving as compiled languages ever (there always will be some cold-start overhead), it's pretty neat programming language, although I now consider lazy PHP developers as planet's nature-killers now :D

[–] onlinepersona@programming.dev 8 points 1 year ago (1 children)

Measure the segfaults per line and the resulting effort to resolve please.

[–] DSTGU@lemm.ee 2 points 1 year ago (1 children)

Rust was designed not to allow issues like that...

[–] onlinepersona@programming.dev 1 points 1 year ago (1 children)

C/C++ on the other hand...

[–] DSTGU@lemm.ee 3 points 1 year ago

Was designed to promote issues like that (happy debugger noises)

[–] 1984@lemmy.today 6 points 1 year ago (1 children)

Yes I will use an energy saving programming language, that will make everything better. /s

[–] vettnerk@lemmy.ml 5 points 1 year ago (1 children)

99% of my code is in perl. My local power source is 100% hydroelectric. I therefore choose to believe that nuclear energy would result in my code quality improving.

[–] palordrolap@kbin.social 3 points 1 year ago (1 children)

"Modern Perls are supposedly faster" I thought, until I checked and apparently they used a very recent Perl.

So now my denial is along the lines of "Well they're asking Perl to do things it doesn't need to, like implementing merge sort and binary trees, and, and!, TIMTOWTDI! They're probably choosing a slow way to do things too!"

The other denial idea was: "Interpreted languages offer rapid prototyping and easier debugging, which saves energy during the development process, and that isn't being taken into account here."

...but then I see the ridiculously low scores for JavaScript. I wonder if Perl (or other interpreted languages) had received the amount of scrutiny and attention that JS has had in order that browsers remain relatively fast, whether it would be any faster now.

[–] vettnerk@lemmy.ml 1 points 1 year ago

Don't know, and to be frank I don't feel so strongly about it either. I use perl because it's the language I happened to become fluent in some twenty years ago, and nowadays when I want to put together a simple utility script in python I usually just say "meh, fuckit" after ten minutes and finish it in perl instead.

[–] Commiunism@lemmy.wtf 3 points 1 year ago* (last edited 1 year ago)

Surprised to see JS so high up, I expected for it to be much closer to PHP.

[–] wim@lemmy.sdf.org 2 points 1 year ago (1 children)

Odd to see the gap between C and Pascal this big. Is this a matter of lacking optimization effort for less popular languages?

[–] spauldo@lemmy.ml 1 points 1 year ago

That, and they might be using Object Pascal. I don't know (I haven't touched Pascal in thirty years) but I would not be surprised if there's some overhead there.

the amusingly sharp contrast of python in terms of memory efficiency vs time and energy makes me think its gc is working overclocked.