DEV Community

Discussion on: The Great Prime Number Challenge: Which Programming Language is the Fastest?

Collapse
 
codenameone profile image
Shai Almog

The numbers don't make sense. JITs take time and Rust should be closer to C. Looking at the rust code it seems that for C you pre-allocate the result heap but in rust you use a vector which will mean it will constantly need to resize the heap.

In Java you used ArrayList<Integer> which isn't the equivalent of the C code so int[] pre-allocated should be faster and closer to the C style.

Still, I don't get why the C code will perform so badly. Did you try with O2, O3 etc.?

Collapse
 
kschneider0 profile image
Kyle Schneider

Thank you for your comment and for pointing out some potential issues with my experiment. As I mentioned in the post, there are many factors that can influence the performance of code, and I maintain that the results I presented should be taken with a grain of salt.

I appreciate your observations about the differences in the implementation of the code across languages, and I agree that this could have contributed to the discrepancies between C, Rust, and Java. I did not even think about this when I generated all the other codes from Python using ChatGPT. The points you made are certainly valid factors to consider when comparing the performance of these languages.

Additionally, I acknowledge that my use of the standard gcc compiler for C may not have been the most optimal choice. I did not even consider choice of compiler, but this could certainly be an interesting avenue for future investigation.