I have been trying to make 3D drawing library for python 3, using Pygame. I want to use Z-Buffer so I need to call function for each pixel that should be drawn. Problem is that drawing 100x100 pixel rectangle takes more than 1 millisecond. Drawing function for rectangle is nested loop with function call and it can be simplified to this code to show the biggest bottleneck:
def another_function():
pass
def test_function():
for j in range(100):
for k in range(100):
another_function()
Function another_function() which does nothing is called 10000 times total. When I measured execution time, timeit has shown that test_function() takes 1.09 millisecond. This is too long because it is necessary to draw multiple rectangles and to achieve 60 frames per second, one frame must take less than 17 milliseconds.
I tried searching for solutions but I have been unable to find any way to increase speed of nested for loops with function calls besides using PyPy and Cython.
Additional information: I am using Python 3.5.2 with Windows 10 64-bit as OS. I didn't find any installer for PyPy for Windows and Cython has problem when compiling modules converted to .c so I can't use it.