I have a very large dataset and I have to iterate over data. I am using very simple for loop in python as shown following. The problem is that it takes 11 seconds to finish. I tested code in Java and it takes only 4 milliseconds. There is a huge difference. So the question is how to use an efficient loop in python?
Here is the Python code and it prints "--- 11.902626514434814 seconds ---"
import time
start_time = time.time()
val = 0
for i in range(1, 17000):
for j in range(1, 13000):
val = 0
print("--- %s seconds ---" % (time.time() - start_time))
Here is the Java code and it prints "4":
long startTime = System.nanoTime();
int x = 0;
for (int i = 0; i < 17000; i++) {
for (int j = 0; j < 13000; j++) {
x = 0;
}
}
long endTime = System.nanoTime();
System.out.println((endTime - startTime) / 1000000);