I’ve seen Java being used on a Raspberry Pi and was curious to see how well it worked on my BeaglePlay board. Here are the results.
In this test I created a basic hello world program and used Java to run the script without compiling it first. So basically, Java compiles and then executes, which demonstrates SBC compute speed based on resource availability.
public class HelloWorld {
public static void main (String[] args) {
String txt = "Hello World";
System.out.println(txt);
}
}
To execute I used:
java Filename.java
My Raspberry Pi 4 board, which uses Java 17, was able to execute in approx. 3 to 4 seconds, while my BeaglePlay board (using Java 11) took approx. 5 to 6 seconds to execute.
As such, I am trying to understand the reasons for the slower performance on the BeaglePlay and whether there’s anything I can tweak on the BeaglePlay to achieve similar results to a Raspberry Pi 4.
You must do your experiment in an “apples to apples” state.
Post your setups for both boards including image versions and such.
Your result of 3 to 4 seconds is pretty slow here is c code version for you to test.
#include <stdio.h>
#include <stdlib.h>
/*
*
*/
int main(int argc, char** argv) {
printf("Hello this is test 1");
return (EXIT_SUCCESS);
}
Run this on all your boards using this line to start it:
:/home/test-delete# time ./test-hello
Hello this is test 1
real 0m0.025s
user 0m0.000s
sys 0m0.021s
That is on a 32 bit SBC.
Here is X86
fred@eng-dev6:~/delete-tests$ time ./test-hello
Hello this is test 1
real 0m0.001s
user 0m0.001s
sys 0m0.000s
Same source.
Precede your binary with time for the exact run time.
As @benedict.hewson stated the version is very critical. Java was not designed for speed, it is for multiplatform. If you need portability and not speed java is a good solution.
For me to get into java the license is $1200 per year…We just don’t have a need for it. I did just look at their site and they are upto version 21. If you can get the latest on both machines that would be the best.
Also, buy some books. Plenty of the stuff on the internet is stale and much of it is crazy stuff, its easy to spend hours chasing your tail.
For what it’s worth… the delay is caused by the compile process.
Tested using javac HelloWorld.java. This took +6 seconds.
Then it was instant to run the executable java HelloWorld.
No doubt there’s optimisations available to improve this “just-in-time” compilation, but I’ve not found, or better yet… I should just stick with running an java executable.
I just completed a test, using the verbose flag on my laptop, Raspberry Pi and BeaglePlay. Just a pure guess, but at first glance the slower speed seems to be file read related.
The am62 soc is superior to the pi4 so it must be something in the deb 11 image. Can you go backwards on the pi with a deb 11 image?
I was going to test that on our other boards and the meta-java layer stops at 8. Based upon that, I would say that java is for the most part going extinct on embedded stuff. If many developers are using it they would have a more current version in yocto. It might have some issues that cannot be resolved easily or cost effectively and that might be displayed in your testing.
I suspect the SoC is adding to that too, as @RobertCNelson pointed out the different cores that I did not take into consideration at the time of stating how the good the am62 is.
Kernel config is extremely important too, for example those selling boards using “speed comparisons” as the focal point of their marketing are turning off critical resources of the kernel in order to optimize what ever metric they want to look good. Buy the board, then you have to turn on the features so ip tables and UFW work and the board is now same as everyone else in that class…
Have you performed testing on the Pi 5, I have one here and only thing I did with it was too light it up on Ubuntu 23.
I don’t see a version 21 yocto recipe either. They have made everything so confusing its not even funny. Many years ago I was a strong supporter of Sun, Solaris was great and the SPARC hardware was the best we could get at that time. Then the java license issue, I still don’t understand what happened. All I see is $$$$ when on the oracle website.
Here is another screen shot that explicitly states a subscription is required.