Recent

Author Topic: Raytracing: FPC vs Java  (Read 10755 times)

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1030
    • Burdjia
Re: Raytracing: FPC vs Java
« Reply #15 on: February 05, 2017, 02:40:30 pm »
Also try out ppcjvm. FPC is a jvm language too.. With sometimes indeed much faster results compared to true native code.
This puzzled me a lot.  How is it possible an interpreted/virtual machine program is faster than native code?  It should be slightly slower.  Even using "Just in time compile" mode.
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

Leledumbo

  • Hero Member
  • *****
  • Posts: 8244
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Raytracing: FPC vs Java
« Reply #16 on: February 05, 2017, 03:21:52 pm »
Also try out ppcjvm. FPC is a jvm language too.. With sometimes indeed much faster results compared to true native code.
This puzzled me a lot.  How is it possible an interpreted/virtual machine program is faster than native code?  It should be slightly slower.  Even using "Just in time compile" mode.
JIT could win in tight loops or complex calculations, as the VM can decide the best instruction sequence to use at runtime according to the machine where it runs.

Thaddy

  • Hero Member
  • *****
  • Posts: 10276
Re: Raytracing: FPC vs Java
« Reply #17 on: February 05, 2017, 04:39:17 pm »
This puzzled me a lot.  How is it possible an interpreted/virtual machine program is faster than native code?  It should be slightly slower.  Even using "Just in time compile" mode.

http://forum.lazarus.freepascal.org/index.php/topic,35022.msg230871.html#msg230871
Well in this thread I wrote an example that compiled with ppcjvm on a Raspberry pi 3 on Oracle hotspot runs twice as fast as ppcarm compiled armhf-vppv4 code with all proper optimizations.
I am more like donkey than shrek

lainz

  • Hero Member
  • *****
  • Posts: 3636
    • Lainz
Re: Raytracing: FPC vs Java
« Reply #18 on: February 05, 2017, 05:18:48 pm »
I need to benchmark V8. I'm using Electron to make small desktop web based applications. It's pretty fast even with large DOM.

I can use Type Script for the classes but I didn't needed it too much.

Java also can have a web browser, also FPC, but I didn't find a way to use them like in Electron.

I'm not used to node.js so I'm not using any third party library, pure JS.

Edit: sorry is not directly related to raycasting, but with benchmarks is.
https://lainz.github.io - My Website
https://lazpaint.github.io/ - LazPaint Downloads

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8583
  • FPC developer.
Re: Raytracing: FPC vs Java
« Reply #19 on: February 05, 2017, 05:34:56 pm »
JIT could win in tight loops or complex calculations, as the VM can decide the best instruction sequence to use at runtime according to the machine where it runs.

Theoretically yes, in practice that barely happens for x86. The codegenerator of JVM is simply better. If you don't have dynamic allocation, the problem of codegeneration is the same as for C and Pascal.

I regularly test against Delphi (which is not really know to be a speedmonster either), and usually FPC lags there, though there are exceptions.


lainz

  • Hero Member
  • *****
  • Posts: 3636
    • Lainz
Re: Raytracing: FPC vs Java
« Reply #20 on: February 05, 2017, 06:32:29 pm »
According to this tool, https://github.com/mrdoob/stats.js/

The JavaScript version http://jsrun.it/notch/dB1E, runs constantly at 60 fps. I didn't change the resolution, is the original one.

If I change that to 640x400 it runs at 31-33fps. (of course you need to save the website, edit the sources, width and height in css, width and height in canvas and width and height in code, then run in a local server with this script in the console:

Code: Pascal  [Select][+][-]
  1. javascript:(function(){var script=document.createElement('script');script.onload=function(){var stats=new Stats();document.body.appendChild(stats.dom);requestAnimationFrame(function loop(){stats.update();requestAnimationFrame(loop)});};script.src='//rawgit.com/mrdoob/stats.js/master/build/stats.min.js';document.head.appendChild(script);})()

).

Java version runs at 28-31 fps on my machine. (Latest Java 64 bit).

I have 2 theories:
- Notch is really a good programmer, even in javascript he did the best code?
- JavaScript in Chrome is really faster than FPC and Java?
- I need to try with Java 32 bit?
« Last Edit: February 05, 2017, 07:00:14 pm by lainz »
https://lainz.github.io - My Website
https://lazpaint.github.io/ - LazPaint Downloads

Leledumbo

  • Hero Member
  • *****
  • Posts: 8244
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Raytracing: FPC vs Java
« Reply #21 on: February 05, 2017, 07:08:42 pm »
JIT could win in tight loops or complex calculations, as the VM can decide the best instruction sequence to use at runtime according to the machine where it runs.

Theoretically yes, in practice that barely happens for x86. The codegenerator of JVM is simply better. If you don't have dynamic allocation, the problem of codegeneration is the same as for C and Pascal.

I regularly test against Delphi (which is not really know to be a speedmonster either), and usually FPC lags there, though there are exceptions.
Right, as GCC/Clang still wins against Oracle JVM even in microbenchmarks.

Akira1364

  • Hero Member
  • *****
  • Posts: 540
Re: Raytracing: FPC vs Java
« Reply #22 on: February 06, 2017, 12:57:39 am »
According to this tool, https://github.com/mrdoob/stats.js/

The JavaScript version http://jsrun.it/notch/dB1E, runs constantly at 60 fps. I didn't change the resolution, is the original one.

If I change that to 640x400 it runs at 31-33fps. (of course you need to save the website, edit the sources, width and height in css, width and height in canvas and width and height in code, then run in a local server with this script in the console:

Code: Pascal  [Select][+][-]
  1. javascript:(function(){var script=document.createElement('script');script.onload=function(){var stats=new Stats();document.body.appendChild(stats.dom);requestAnimationFrame(function loop(){stats.update();requestAnimationFrame(loop)});};script.src='//rawgit.com/mrdoob/stats.js/master/build/stats.min.js';document.head.appendChild(script);})()

).

Java version runs at 28-31 fps on my machine. (Latest Java 64 bit).

I have 2 theories:
- Notch is really a good programmer, even in javascript he did the best code?
- JavaScript in Chrome is really faster than FPC and Java?
- I need to try with Java 32 bit?

I think most people in this thread are forgetting that the HTML5 Canvas element is hardware accelerated, and any JavaScript code passed to it is likely optimized behind the scenes and compiled into some kind of GPU-friendly data structure. It's important to keep in mind that Chrome (and all other major browsers) are in fact "native" desktop applications written in C++. This is in contrast to the SDL-based ports we've seen here, which are explicitly not hardware accelerated (even though they're also native applications and easily could be), and simply blit each individual pixel to the SDL surface one by one. The same applies to the Java version: hardware acceleration is not enabled by default in the Java "Graphics" API.
« Last Edit: February 06, 2017, 03:59:21 am by Akira1364 »

argb32

  • Jr. Member
  • **
  • Posts: 89
    • Pascal IDE based on IntelliJ platform
Re: Raytracing: FPC vs Java
« Reply #23 on: February 06, 2017, 01:48:12 am »
I have 2 theories:
- JavaScript in Chrome is really faster than FPC and Java?

JavaScript in general should be slower than Java or FPC due to language features.
The JS version is not identical to my versions which identical to each other.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8583
  • FPC developer.
Re: Raytracing: FPC vs Java
« Reply #24 on: February 09, 2017, 10:26:02 am »
I have 2 theories:
- JavaScript in Chrome is really faster than FPC and Java?

JavaScript in general should be slower than Java or FPC due to language features.

What happens here might be the same as the principle for asm.js:  if you only use a certain optimizable subset that is highly optimizable, what ends up at the codegenerator is the same as it would be from a Java, pascal or C/C++ program.

Then it is just codegenerator vs codegenerator, and the language doesn't really matter much.

lainz

  • Hero Member
  • *****
  • Posts: 3636
    • Lainz
Re: Raytracing: FPC vs Java
« Reply #25 on: February 10, 2017, 12:30:21 am »
Good to know.
https://lainz.github.io - My Website
https://lazpaint.github.io/ - LazPaint Downloads

 

TinyPortal © 2005-2018