Recent

Author Topic: FP vs Java Benchmark  (Read 28838 times)

Jay

  • New Member
  • *
  • Posts: 31
Re: FP vs Java Benchmark
« Reply #45 on: December 07, 2016, 01:55:56 pm »
I'm currently learning Java as well as FP & Lazarus and was curious about the performance of Java compared to FP so thought I'd compare the times to find 100,000 primes. Code for FP:

Code: Pascal  [Select][+][-]
  1.   for i := 1 to LIMIT do

Now the Java code (using version 1.8 of the JRE)
Code: Javascript  [Select][+][-]
  1.     for(int i = 1; i < limit; i++)


Open your eyes, the bigger, the wider you can !!
After a while you'll see something funny...

oops. It makes very little difference to the results though.

Jay

  • New Member
  • *
  • Posts: 31
Re: FP vs Java Benchmark
« Reply #46 on: December 07, 2016, 01:59:53 pm »
Of course, but generally you would expect native code to out-perform a VM because a VM has an extra layer of abstraction. For the same reason you would expect assembly language to out-perform C.
Today's compilers (at least a few of the major ones) are pretty darn impressive with how they can produced performance ready code. As for your statement amount assembly language - that's highly dependent on the skills of the developer. If I had to try and write assembly now (haven't done so for a very long time), it will mist likely be crap. :)

Quote
https://benchmarksgame.alioth.debian.org/u64q/pascal.html
So because Java beats FP here on most algorithms, is it fair to conclude that Java is a "faster" language than FP? I don't think so.
But the proof is right there in the benchmark results, so how can you still have doubts? ;-)

Because we haven't seen the code, and we don't know which compiler switches were used. E.g. when I re-ran my code with -O3 optimisation it turned out that FP was faster after all.

BTW, I really like your fpGUI toolkit.  :)
« Last Edit: December 07, 2016, 02:01:46 pm by Jay »

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: FP vs Java Benchmark
« Reply #47 on: December 07, 2016, 02:56:21 pm »
If you want jvm, just use FPC for JVM.....Difference gone..... See my example code. Comparing apples and pears. >:D >:D
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

guest58172

  • Guest
Re: FP vs Java Benchmark
« Reply #48 on: December 07, 2016, 04:39:54 pm »
I'm currently learning Java as well as FP & Lazarus and was curious about the performance of Java compared to FP so thought I'd compare the times to find 100,000 primes. Code for FP:

Code: Pascal  [Select][+][-]
  1.   for i := 1 to LIMIT do

Now the Java code (using version 1.8 of the JRE)
Code: Javascript  [Select][+][-]
  1.     for(int i = 1; i < limit; i++)


Open your eyes, the bigger, the wider you can !!
After a while you'll see something funny...

oops. It makes very little difference to the results though.

halstead complexity for Pascal:
for, :=, to: 3 operators.
i, 1 , limit: 3 operands

halstead complexity for Java:
for, = , <, ++: 4 operators
i, 1, limit: 3 operands

Statistically speaking the Pascal for  in this case is less error prone.

But let's take a real case:

Code: Pascal  [Select][+][-]
  1.   for i := 0 to LIMIT-1 do

for this case, for, :=, to, - : 4 operators.
for this case, i, 0 , LiMIT, 1: 4 operands.

Code: Javascript  [Select][+][-]
  1.     for(int i = 0; i < limit; i++)

for this case, for, =, < , ++: 4 operators too.
for this case, 0, i limit: 3 operands

 %)

Is it really more simple ?
 ;)

When we remove the error we have Pascal more complex for a for.

Nitorami

  • Sr. Member
  • ****
  • Posts: 496
Re: FP vs Java Benchmark
« Reply #49 on: February 06, 2017, 12:18:35 pm »
Quote
Quote

Quote
https://benchmarksgame.alioth.debian.org/u64q/pascal.html
So because Java beats FP here on most algorithms, is it fair to conclude that Java is a "faster" language than FP? I don't think so.

But the proof is right there in the benchmark results, so how can you still have doubts? ;-)

Rather than simply comparing runtimes, it would be fair to consider the runtime per CPU used, and then FPC and Java appear pretty much on par for all tests, sometimes in favour of Java, sometimes FPC, with one exception, the Mandelbrot. I had a look into that and believe the reason is again (similar to the SDL "tunnel" program) that Java can benefit of SSE vectorization. When looking at the Java code, I wondered why the inner loop calculates two points at a time. This would have no benefit in Pascal, but the intent is probably to help the engine to vectorise it and perform the two calculations simultaneously.

            double nZr1=Zr1*Zr1-Zi1*Zi1+Crb[x+i];
            double nZi1=Zr1*Zi1+Zr1*Zi1+Cib[y];
            Zr1=nZr1;Zi1=nZi1;

            double nZr2=Zr2*Zr2-Zi2*Zi2+Crb[x+i+1];
            double nZi2=Zr2*Zi2+Zr2*Zi2+Cib[y];
            Zr2=nZr2;Zi2=nZi2;

Where vectorization is not possible, there is no big difference in performance relative to CPU performance.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: FP vs Java Benchmark
« Reply #50 on: February 06, 2017, 02:18:42 pm »
Both a modern browser's javascript engine and a Oracle hotspot jvm can and will offload *a lot* to the GPU. Atm this is not always possible yet in pure Pascal written code. (It works with jvm target!)
Current FPC supports modern FPU's, though. In my experience you can achieve good results by tweaking algorithms and FPU settings on a per platform basis.
And be aware of optimizations that FPC currently does not perform yet, or partially. These are often well documented.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

argb32

  • Jr. Member
  • **
  • Posts: 89
    • Pascal IDE based on IntelliJ platform
Re: FP vs Java Benchmark
« Reply #51 on: February 06, 2017, 03:27:44 pm »
Both a modern browser's javascript engine and a Oracle hotspot jvm can and will offload *a lot* to the GPU.

Hotspot doesn't do any transparent use of GPU. Most likely browser Javascript engines too.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: FP vs Java Benchmark
« Reply #52 on: February 06, 2017, 03:45:33 pm »
Hotspot doesn't do any transparent use of GPU. Most likely browser Javascript engines too.

Wrong: both do. Hotspot uses e.g. opencl on certain platforms. Google browsers do the same. OpenCL uses the GPU.
You'll need to have the cutting edge, but "project Sumatra" as this is called is already live on some platforms.
On Raspberry Pi, Google optimized Chrome and Oracle optimized Hotspot using similar technology to utilize the GPU for calculations.

And it is completely transparent to the high level language. No need to play with e.g. OpenCL calls yourself.

Quote from the Oracle employed project lead:
"The HotSpot compiler will now have the capability to compile code for the GPU," explains Frost. "We don't have to target a particular device because the JVM is making the decision at runtime."

It is just a compiler directive, not a language change.
« Last Edit: February 06, 2017, 03:54:54 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

argb32

  • Jr. Member
  • **
  • Posts: 89
    • Pascal IDE based on IntelliJ platform
Re: FP vs Java Benchmark
« Reply #53 on: February 06, 2017, 06:30:19 pm »
You'll need to have the cutting edge, but "project Sumatra" as this is called is already live on some platforms.

It's interesting project but it seems abandoned now. And there is no any switches to turn on this optimization on current JVM implementations. May be some special builds from branches of OpenJDK.

"The HotSpot compiler will now have the capability to compile code for the GPU," explains Frost. "We don't have to target a particular device because the JVM is making the decision at runtime."

It was said years ago when people believed in bright future of massive-multicore PCs with appropriately designed software. Only such software can benefit from GPU. But that didn't happen for some reason.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: FP vs Java Benchmark
« Reply #54 on: February 06, 2017, 07:24:42 pm »

Code: Javascript  [Select][+][-]
  1.     for(int i = 0; i < limit; i++)

for this case, for, =, < , ++: 4 operators too.
for this case, 0, i limit: 3 operands

5 operands, i three times, and grammar accepts other values for i (so they are separate error possibilities)

Is it really more simple ?
 ;)

Yes, toss javascript :)


Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: FP vs Java Benchmark
« Reply #55 on: February 06, 2017, 08:35:53 pm »

It's interesting project but it seems abandoned now. And there is no any switches to turn on this optimization on current JVM implementations. May be some special builds from branches of OpenJDK.

It's not: current work - or spin-off thereof - has been used already. Wait for Java 9 to see it in production Hotspots (or test the special release of the Hotspot on a RaspberryPi 3: enabled by default on Raspbian)
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018