My project involves heavy looping over stocks and stat calculations. It was written in python3. As the data gets bigger, I feel the script performance is quite slow. I attempted lua because of its fame on speed, and tried to do some tests as below, also compared to python2 as a benchmark.
Only a simple loop as a test code:
lua version
for i=1,100,1 do
for j=1,100,1 do
print(i*j)
end
end
python version
for i in range(1,101):
for j in range(1,101):
print(i*j)
the results are as follows (tried a few time and pick the best for each group):
lua5.2.3: 0.461sec
python2.7.6: 0.429sec
python3.4: 0.85sec
What surprised me is that python2 is around 2x faster than python3.
Why? and even with a simple loop?
I thought python3 is the future for python, so I learned python3 from the beginning.
Do I really need to port back my code to python2, or any tweak I could with looping to enhance its performance in python3?