top | item 46843168

(no title)

KerrAvon | 1 month ago

Why are you surprised? Java always suffers from abstraction penalty for running on a VM. You should be surprised (and skeptical) if Java ever beats C++ on any benchmark.

discuss

order

pron|1 month ago

The only "abstraction penalty" of "running on a VM" (by which I think you mean using a JIT compiler), is the warmup time of waiting for the JIT.

xigoi|1 month ago

The true penalty of Java is that product types have to be heap-allocated, as there is no mechanism for stack-allocated product types.

andersmurphy|1 month ago

Its a statement of our times that this is getting down voted. JIT is so underrated.

woooooo|1 month ago

For the most naive code, if you're calling "new" multiple times per row, maybe Java benefits from out of band GC while C++ calls destructors and free() inline as things go out of scope?

Of course, if you're optimizing, you'll reuse buffers and objects in either language.

igouy|29 days ago

> maybe Java benefits from out of band GC

benchmarks game uses BenchExec to take 'care of important low-level details for accurate, precise, and reproducible measurements' ….

BenchExec uses the cgroups feature of the Linux kernel to correctly handle groups of processes and uses Linux user namespaces to create a container that restricts interference of [each program] with the benchmarking host.

cryptos|1 month ago

In the end, even Java code becomes machine code at some point (at least the hot paths).

stefs|1 month ago

yes, but that's just one part of the equation. machine code from compiler and/or language A is not necessarily the same as the machine code from compiler and/or language B. the reasons are, among others, contextual information, handling of undefined behavior and memory access issues.

you can compile many weakly typed high level languages to machine code and their performance will still suck.

java's language design simply prohibits some optimizations that are possible in other languages (and also enables some that aren't in others).