fell,
@fell@ma.fellr.net avatar

Is really more efficient than ? Does anyone have data on this?

juliangonggrijp,

@fell The computer language benchmarks game supports this statement. If you scroll down a bit on this page, you will see that Node.js executes faster than PHP (both server). https://benchmarksgame-team.pages.debian.net/benchmarksgame/box-plot-summary-charts.html

So it is faster, for the particular benchmarks that are run in that game, given the implementations that volunteers have contributed. It does not automatically mean that JS is better; speed is not the only thing that matters.

fell,
@fell@ma.fellr.net avatar

@juliangonggrijp This is a very useful website which also makes it obvious that the performance of a language isn't easy to determine. It's still interesting.

I'm surprised that seems to be significantly slower than or #C. Vut that could be due to vector instructions or things like that.

teotwaki,
@teotwaki@mastodon.online avatar

@fell @juliangonggrijp Why are you that surprised?

fell,
@fell@ma.fellr.net avatar

@teotwaki @juliangonggrijp I always thought Go and Rust would be somewhat similar because both just compile down to CPU instructions. So there wouldn't be much difference. Which - based on this data - seems true for C/C++ and Rust, but not for Go.

mo8it,
@mo8it@fosstodon.org avatar

@fell @teotwaki @juliangonggrijp Optimized Rust code will always be faster than optimized Go code. Go has a runtime with garbage collection which Rust doesn't have.

In addition, Rust allows you to go as low level as you want/need. But you can also stay relatively high level.

teotwaki,
@teotwaki@mastodon.online avatar

@mo8it @fell @juliangonggrijp It also depends what you’re benchmarking. Rust/Go/C will blow Node/Python/Ruby/Java out of the water when it comes to startup cost (process start time), but a tight inner loop in a warm JVM can give C a run for its money.

fell,
@fell@ma.fellr.net avatar

@teotwaki @mo8it @juliangonggrijp I do not believe that a JVM can ever beat an optimized C program. This would imply that the C compiler is generating suboptimal machine code or the JVM has knowledge that the C compiler does not have.

Is that what happens? Does the JVM observe the running program and amend the instruction stream to improve performance? I doubt that, but it would be amazing.

juliangonggrijp,

@fell @teotwaki @mo8it Yes, that is what might happen, although I honestly think it is a bit theoretical. Java has such substantial costs compared to C (GC, forced type erasure) that hotspot optimization will probably only compensate for those effects in the simplest loops with low memory intensity. I think those situations will tend to be relatively easy for a C compiler with -O3 as well.

In practice, Java is usually 1.5-2 times slower than C, as demonstrated by the benchmarks game.

teotwaki,
@teotwaki@mastodon.online avatar

@fell @juliangonggrijp Golang is also the only garbage collected language out of all three. I haven’t looked at the benchmark, but that alone can give a serious slow down.

But just to clarify something: it’s not because something gets compiled down to machine code that it is inherently fast (or faster). JIT can perform miracles, and depending on the workload, cache-friendliness can have a dramatic effect.

A good Python program can outperform a bad C one, etc.

fell,
@fell@ma.fellr.net avatar

@teotwaki @juliangonggrijp Of course, good Python can outperform bad C. But what I'm looking for is typical Python vs typical C. Every language has their ways things are typically done, and that's how most code will be written. This unwritten standard is probably the biggest factor when it comes to language performance.

meuon,
@meuon@fosstodon.org avatar

@fell Depens on what you are doing and where. I contend that PHP can be extremely fast and efficient on a server when it doesn't include huge frameworks to load, and JavaScript is your only real choice in a Browser. As it's on the clients computer, you could argue that it's much more efficient that whatever you run on the server. JavaScript on the server: also depends. An F1 racer and a drag car are both efficient. At different things.

hackdefendr,

@fell

I asked ChatGPT with the BING plugin enabled. Here is a shared link to the question and the very detailed answer:

https://chat.openai.com/share/c866642d-9e04-43bf-aa34-b495a30e4141

Crell,
@Crell@phpc.social avatar

@hackdefendr @fell That's a not-unreasonable summary for . 🙂

At the raw code-execution level, PHP and JS are very comparable these days, AFAIK. And both are far ahead of Python or Ruby.

PHP is usually not async, though it can be. JS is always async. Depending on the use case, that may or may not impact overall performance. PHP's modern async has fewer DX problems compared to JS, but it's still new and not widely used.

schizanon,
@schizanon@mas.to avatar

@fell at what?

fell,
@fell@ma.fellr.net avatar

@schizanon execution time

schizanon,
@schizanon@mas.to avatar

@fell execution of what? A Fibonacci sequence?

fell,
@fell@ma.fellr.net avatar

@schizanon I just mean, If one were to write any program in JavaScript and PHP, which would execute faster on the same hardware?

Of course it depends on what it is, but depending on the program one or the other would be faster.

Let's say a JSON parser and a compression algorithm.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • javascript
  • Durango
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • tacticalgear
  • khanakhh
  • Youngstown
  • mdbf
  • slotface
  • rosin
  • everett
  • ngwrru68w68
  • kavyap
  • InstantRegret
  • JUstTest
  • cubers
  • GTA5RPClips
  • cisconetworking
  • ethstaker
  • osvaldo12
  • modclub
  • normalnudes
  • provamag3
  • tester
  • anitta
  • Leos
  • megavids
  • lostlight
  • All magazines