r/programming • • Jan 16 '20

Records Come to Java

https://blogs.oracle.com/javamagazine/records-come-to-java
59 Upvotes

65 comments sorted by

View all comments

Show parent comments

0

u/couscous_ Jan 18 '20

It's a good start don't get me wrong, but it's running on an outdated CPU. I ran some benchmarks myself where golang was quicker than Java in the benchmarks page, and I got the opposite result.

2

u/igouy Jan 18 '20

Specifically ?

(The details always matter.)

1

u/couscous_ Jan 18 '20 edited Jan 18 '20

I ran the spectral norm benchmark (input size 30000) with the following result:

golang:

    1.274224153
       18.81 real        70.19 user         0.38 sys

Java (I think it was even version 3, which ran faster for me than version 2 which currently tops the benchmarks list for Java):

    1.274224153
       16.18 real       105.95 user         0.45 sys

and nbody benchmark with input size 60000000:

golang:

-0.169075164
-0.169012474
        6.09 real         6.04 user         0.02 sys

Java:

-0.169075164
-0.169012474
        6.04 real         5.94 user         0.06 sys

I recall seeing a pull request submitted by someone for Java that uses Math.fma which should have speeded up that benchmark (don't recall which one it is, but it's available in the project's list of issues), but because the CPU used to run the benchmarks didn't support it, it actually caused a degraded performance.

The second issue with just relying on microbenchmarks to judge a platform is that they only test out specific parts of said platform, and do not highlight what it's capable of overall. For example, large Java programs do run faster than golang programs because of what the JIT is able to do (inlining, de-virtualization, certain cases of auto-vectorization, etc.), but microbenchmarks don't run long enough to be able to demonstrate this. Other long running Java programs work in high throughput rates (which the golang GC is bad at), again would be difficult to show in microbenchmarks.

2

u/igouy Jan 18 '20 edited Jan 19 '20

I got the opposite result

There's not much difference between the times for those Go and Java spectral-norm programs on the old machine —

spectralnorm.4.go 30000
121.462 elapsed secs 

spectralnorm.2.java 30000
120.786

There's more difference between the times for those Go and Java n-body programs on the old machine, but still not much —

nbody.1.go 60000000
25.506

nbody.5.java 60000000
26.391

Are you surprised that measuring program performance on different machines can give different relative measurements?

… Java that uses Math.fma which should have speeded up that benchmark…

Don't you think that use of FMA would also have speeded up programs written in other languages?

… only test out specific parts of said platform…

That's also true for complete apps.

Program performance measurements are brittle.

What you've said is not specific to the benchmarks game ("And the benchmarks game doesn't count").

… large Java programs do run faster than golang programs…

As you wrote: "Citation needed."