Why is C# a lot faster than Javascript and Java?

Have you checked this benchmark ? https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/javascript.html Javascript vs Java


https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/csharp.html Java vs C#

the Gap actually isn't really wide. And in other benchmark C# and Javascript speed is actually comparable.


Take a look other benchmark : https://github.com/kostya/benchmarks (This one pretty good benchmark for RL scenario)

There are some calc which node.js is faster than C#/Net.core or C#/Mono

https://programming-language-benchmarks.vercel.app/javascript-vs-csharp (this one good too)
While they are good enough sources, they just paint all over the wall.

I'm a professional .net core developer, and I have used both js and .net. The thing is, modern js is actually quite fast but it is severely lacking and imo fundamentally flawed.
It is fast, because you can whip up a js codebase, attach it to node js and see almost the same performance as any other framework until you do something really gritty which is fine for majority of the users majority of the time, like you wouldn't be doing image manipulation in your hobby website.
Trouble is, when you do something gritty like image manipulation, c# gives you cleaner interface to the hardware which nets it a bit more performance, and this stacks up. More so if you use parallelism, js was made as a single threaded language and while modern js offers variety of tools to use multiple tasks or threads, they still have some big caveat here or there and are immensely painful to deal with when they are the source of a bug. And that is amplified by JS' flaw, layman engineering. Everything in js is designed to get a layman easily get going and hit most of his actual development tasks quickly, which is good from a business/product owner perspective as you get a product fast, but from a technical one, it leaves everything up to the compiler/interpreter to define. Stuff like string auto converting to boolean, being able to basically overwrite any data type as immutability is non existent or hoisted variables and so on. All that you don't define, the interpreter does, and when a future update to the said interpreter defines it differently things like transpilation come into place, which have their own list of issues.

This all is to say, there's more to any language than just the benchmarks and benchmarks theirselves are subjective not objective, one author might argue that all languages should use the same base array type in the code, but they might be implemented vastly differently internally, others might argue we use language specific data types as when we would actually use the language we wouldn't try to have the same array as in js and so on. So you can have c# benchmarks where c# blows js out of the park or otherwise where it doesn't, it's all implementation dependent.
While they are good enough sources, they just paint all over the wall.

I'm a professional .net core developer, and I have used both js and .net. The thing is, modern js is actually quite fast but it is severely lacking and imo fundamentally flawed.
It is fast, because you can whip up a js codebase, attach it to node js and see almost the same performance as any other framework until you do something really gritty which is fine for majority of the users majority of the time, like you wouldn't be doing image manipulation in your hobby website.
Trouble is, when you do something gritty like image manipulation, c# gives you cleaner interface to the hardware which nets it a bit more performance, and this stacks up. More so if you use parallelism, js was made as a single threaded language and while modern js offers variety of tools to use multiple tasks or threads, they still have some big caveat here or there and are immensely painful to deal with when they are the source of a bug. And that is amplified by JS' flaw, layman engineering. Everything in js is designed to get a layman easily get going and hit most of his actual development tasks quickly, which is good from a business/product owner perspective as you get a product fast, but from a technical one, it leaves everything up to the compiler/interpreter to define. Stuff like string auto converting to boolean, being able to basically overwrite any data type as immutability is non existent or hoisted variables and so on. All that you don't define, the interpreter does, and when a future update to the said interpreter defines it differently things like transpilation come into place, which have their own list of issues.

This all is to say, there's more to any language than just the benchmarks and benchmarks theirselves are subjective not objective, one author might argue that all languages should use the same base array type in the code, but they might be implemented vastly differently internally, others might argue we use language specific data types as when we would actually use the language we wouldn't try to have the same array as in js and so on. So you can have c# benchmarks where c# blows js out of the park or otherwise where it doesn't, it's all implementation dependent.
Well this is why Typescript exist.
Well this is why Typescript exist.
TS compiles to js... which isn't putting it much differently from js. You can get a lot of syntactic sugar with TS but at the end of the day, it's all going into JS, it helps the developer a lot but not the machine. It still stinks where JS does though, but that's just a personal preference.

If we are talking about languages that compile to js anyway, Dart is a good candidate too. It can compile to javascript and with a little bit of effort even use other js packages in Dart code itself. Dart being a much more well defined language ( by well defined i mean things like strings can't just be directly booleaned or streams/async hells are identified by statical analysis of the IDE itself, plus some other things) allows a lot more flexibility imo.
Kinda makes sense since C# has been around back since computers were still made of stone. Even when the biggest computer nerd in the world was convinced we would never need more than 640 kb* ram, C# was already in use for over a decade.

(*Yes, that is not gigabytes, not even megabytes That is kilobytes.)
Kinda makes sense since C# has been around back since computers were still made of stone. Even when the biggest computer nerd in the world was convinced we would never need more than 640 kb* ram, C# was already in use for over a decade.

(*Yes, that is not gigabytes, not even megabytes That is kilobytes.)
I think you're maybe thinking about something else. C# isn't really that old. Both Java and JavaScript are older than C#.

Regardless, I wouldn't choose any of those 3 languages if I were particularly concerned about speed, so I find this thread kinda moot.
Kinda makes sense since C# has been around back since computers were still made of stone. Even when the biggest computer nerd in the world was convinced we would never need more than 640 kb* ram, C# was already in use for over a decade.
Yeah, you might be confused with C. C# was new when I was graduating from high school, 2000. Computers absolutely had megabytes of RAM at that point.
Oh, you guys are right. That was C, Not C#.
Oops.
if we take a look from recent web framework benchmark, Javascript is actually very very fast (Thanks to V8 Engine).

https://www.techempower.com/benchmarks/#section=data-r21&hw=ph&test=composite

Take a look at this benchmark. Javascript got rank number 1, beating other web framework from programming language like C++ and Rust.
C# is not necessarily inherently faster than JavaScript and Java. The performance of a programming language depends on various factors, including the execution environment, the efficiency of the compiler or interpreter, the optimization techniques used, and the specific use case. JavaScript and Java are widely used in different domains, and each has its own strengths and weaknesses.

When it comes to performance, JavaScript, which is primarily used in web browsers, has made significant advancements in recent years. Modern JavaScript engines, such as Google's V8 (used in Chrome) and Mozilla's SpiderMonkey (used in Firefox), have become highly optimized and can execute JavaScript code quite efficiently. Additionally, JavaScript benefits from just-in-time (JIT) compilation, which dynamically compiles JavaScript code to machine code during runtime, improving its performance.

Java, on the other hand, is known for its "write once, run anywhere" philosophy and has been extensively used in enterprise-level applications. Java programs are typically compiled to bytecode, which is then executed by the Java Virtual Machine (JVM). JVMs employ various optimization techniques, such as just-in-time compilation and adaptive optimization, to improve the performance of Java applications. Java also provides a vast ecosystem of libraries and tools that can aid in optimizing performance.

C#, developed by Microsoft, is primarily used in the .NET framework and is often associated with Windows development. C# programs are compiled to Intermediate Language (IL), which is then executed by the Common Language Runtime (CLR). The CLR provides features like just-in-time compilation, garbage collection, and runtime optimization, which can enhance the performance of C# applications. Additionally, C# benefits from being statically typed, which allows for more efficient memory management and can result in better performance in certain scenarios.

It's worth noting that the performance differences between these languages can vary based on the specific use case. For computationally intensive tasks or low-level system programming, languages like C++ may be preferred due to their closer proximity to the hardware. Ultimately, the choice of programming language should be based on factors such as the requirements of the project, the existing codebase, the development team's expertise, and the available tools and libraries, rather than assuming that one language is universally faster than others.
C# and Java both compiles to an intermediary language (C# => MSIL, Java => Java bytecode).
This intermediary language is platform agnostic so you only have to compile once. Developer efficiency is not an issue you have to consider since they live in the C#/Java world, instead you have a format that is designed for efficient Just-In-Time native/platform specific code of whereever the code happen to be executed.

The V8 JavaScript Engine essentially works by compiling JavaScript source code on the fly into V8 bytecode before following the JIT => execution path.

Original thread: https://forums.rpgmakerweb.com/threads/why-is-c-a-lot-faster-than-javascript-and-java.91070/