I have a Python code below and it hits out of memory error for 100Mil loop append. Java with same code doesn't have this issue at all without any tuning.
Anyway to tune using the python command or like Java Hotspot JVM Command?
Anyway to tune using coding way to make it run faster and utilize lesser memory.
import datetime;
mylist = []
before = datetime.datetime.now()
for _ in range(100000000):
mylist.append(datetime.datetime.now())
print("List length-->" , len(mylist))
after = datetime.datetime.now()
print ('Python time taken in seconds--->', (after - before).seconds)
Post notes:
Memory leak detection on this "datetime.datetime.now()"
Sharing my java code here. It works more than 10 times faster without JVM tuning yet and process completed in about 6 seconds .
Anyway, Java does a much better garbage collection job than Python. Normally Java won't crash in this kinda simple operation since 20 years back. https://www.snaplogic.com/glossary/python-vs-java-performance
Note: Change from System.currentTimeMillis() to New Date() doesn't make different.
package demo;
import java.util.ArrayList;
import java.util.List;
public class Performance {
public static void main(String[] args) {
List<Long> mylist = new ArrayList<Long>();
long before = System.currentTimeMillis();
for (int i = 0; i < 100000000; i++) {
mylist.add(System.currentTimeMillis());
}
long after = System.currentTimeMillis();
System.out.println("Java time taken in miliseconds--->" + (after - before) );
}
}