What happens if you don't use the os.system
call?
for me:
python test.py 10 # 0.14
python test.py 100 # 1.18
python test.py 1000 # 11.77
It grows approximately an order of magnitide each time without os.system
. So, I'd say your problem is in the system call, not the performance of numpy (This is confirmed by doing the same test over except this time commenting out the numpy portion of the code). At this point, the question becomes "Why is it slow(er) to do repeated system calls?" ... Unfortunately, I don't have an answer for that.
Interestingly enough, If I do this in bash, there is no problem (it returns almost immediately)...
time for i in `seq 1 1000`; do echo true > /dev/null; done
It also seems that the problem isn't just os.system
-- subprocess.Popen
suffers the same mality... (although, subprocess
may just call os.system
under the hood, I don't actually know...)
EDIT
This is getting better and better. In my previous tests, I was leaving the allocation of the numpy array ... If you remove the allocation of the numpy array also, the test goes relatively fast. However, the allocation of the array (1000,800,800) only takes ~1 second. So, the allocation isn't taking all (or even much of the time) and the assignment of data to the array doesn't take much time either, but the allocation status of the array does effect how long it takes for the system call to execute. Very weird.