r/SoftwareEngineering • u/GPD496AQ • Apr 28 '20
Simple Performance Experiment of Java, C++, and Python, on a Dell Alienware R3
I'm not sure if sharing blog posts or Medium stories on programming is allowed because it's been a very long time since I wrote a Reddit post, and this subreddit doesn't have additional rules. If it isn't please excuse me.
Anyway, this weekend, I did an experiment out of interest to measure the performance of Java, C++, and Python on my Alienware laptop with three simple functions. One that prints out "Hello world," one that does four arithmetic operations and displays the results, and one that instantiates a class and immediately destroys the object. The test bench, where I measure the execution time, uses the native timing algorithms such as the System class in Java.
This Medium story explains what I did in detail and the data I've obtained:
[Link removed because of massive criticism.]
What do you folks get when you do a similar experiment like this one? That's not to say which programming language is the best, but rather, to see what you get.
EDIT: I think I was doing this experiment for fun.
0
Apr 28 '20
Python is an interpreted language, while Java and C++ are compiled languages. Python code has to be translated into intermediate instructions by an interpreter at runtime.
1
u/GPD496AQ Apr 29 '20
I'm a little curious to find out why the times for creating an object and destroying it in Python is zero.
1
Apr 30 '20
The del statement removes the object name and all global references to the object when the program is interpreted, it doesn’t force garbage collection.
https://docs.python.org/3/reference/simple_stmts.html#the-del-statement
1
u/GPD496AQ Apr 30 '20
To force garbage collection, would it be gc.collect()?
1
Apr 30 '20
I haven’t used it before. But I think writing some tests with the Python garbage collection interface will help with your project:
8
9
Apr 28 '20
[removed] — view removed comment
5
u/crosstherubicon Apr 29 '20
How about you cut the drama and start talking to people reasonably and constructively
3
Apr 29 '20
[removed] — view removed comment
0
u/crosstherubicon Apr 30 '20
No one makes you come here.
No one makes you read the posts.
Most importantly, no one makes you reply to anything.
This is a forum for software engineers of all strengths. If its not up to your standards then find somewhere that is.
3
2
u/GPD496AQ Apr 28 '20
A side comment:
Something that isn't right, though: in the test where I instantiated an object and destroyed it, the time difference Python gives me is always zero seconds.
Source code of my Python script:
I wonder why this is happening. I'm not much experienced with Python as compared to Java and C++, so please bear with me.
What is it I can program differently with either the test bench or the objectCreateAndDestroy() function itself?