I am currently selecting a large list of rows from a database using pyodbc. The result is then copied to a large list, and then i am trying to iterate over the list. Before I abandon python, and try to create this in C#, I wanted to know if there was something I was doing wrong.
clientItems.execute("Select ids from largetable where year =?", year);
allIDRows = clientItemsCursor.fetchall() #takes maybe 8 seconds.
for clientItemrow in allIDRows:
aID = str(clientItemRow[0])
# Do something with str -- Removed because I was trying to determine what was slow
count = count+1
Some more information:
- The for loop is currently running at about 5 loops per second, and that seems insanely slow to me.
- The total rows selected is ~489,000.
- The machine its running on has lots of RAM and CPU. It seems to only run one or two cores, and ram is 1.72GB of 4gb.
Can anyone tell me whats wrong? Do scripts just run this slow?
Thanks
clientItemRow[0]
really big? 489,000 is a low of rows, but 5rows/s is laughably slow. Also, someone can correct me if I'm wrong, but I'm pretty sure you're code, as written, will only run on one core, but should still be miles faster than 5 iterations per second. Also, you can use the builtin cProfile to see where you're hitting a bottle-neck. – Klimttype(allIDRows)
return? – Perkins