I made a small test to see the difference between the execution speed of JAVA and JS, | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I made a small test to see the difference between the execution speed of JAVA and JS,

Here the test is not accurate, since JAVA code is running in sololearn server while JS code is running in app. but still it was surprising to see JS code working way too faster than java code. Is my test accurate in any way? and wouldn't the JAVA code running in server be faster than JS code? https://code.sololearn.com/WxwvfhLOYLL1/?ref=app https://code.sololearn.com/coow10J5c8Z9/?ref=app

9th Nov 2021, 3:51 AM
ACE
ACE - avatar
7 Answers
+ 4
Mehran i used String builder and found it works relatively faster than using String. https://code.sololearn.com/cpz5r242cvPG/?ref=app
9th Nov 2021, 12:38 PM
ACE
ACE - avatar
+ 3
zemiak The second test in my code runs inside the function. did you try it? Also use the latest version of Chrome, as well as Android WebView if your device is using it.
12th Nov 2021, 4:50 AM
Mehran
Mehran - avatar
+ 2
Martin Taylor I tested both codes(my code is just a simple for loop) in my mobile . Js was faster. I ran java code on the form of Android App JS takes 2500ms in the function. and Java takes 3500ms . It's wondering for me
9th Nov 2021, 12:31 PM
Mehran
Mehran - avatar
+ 2
Adam McGregor . JS was slower in my mobile before Chrome 94/95 . and I used AOT compilation for java
11th Nov 2021, 4:51 AM
Mehran
Mehran - avatar
+ 1
I also get 3500 ms local java 7 on Android 11 on server is java 16 js takes 5000 both by Mehran codes
11th Nov 2021, 10:17 PM
zemiak
0
Adding on to what Martin Taylor was saying. JS is an interpreted language and has a larger translational overhead. Java is a complied/interpreted. Java by default is complied to a IL which reduces translational overhead. This IL is translated at runtime. This is called a JIT compiler. Java does support a AOT compiler but that's another layer of complexity. Java also has an application start up overhead. TLDR; you can expext Java to run faster than JS in general, but you need to eliminate as many variables in your test to properly reflect this. Like ensuring that the code is run on the same hardware with similar work loads. Properly designed benchmarking software will run the tests many times to eliminate chaotic behaviour.
11th Nov 2021, 2:12 AM
Adam McGregor