我想我找到了一种仍然效率不高但速度更快的迂回方式,这是我的新计数测试与从控制台捕获的旧计数测试:
trying to login to google sheets
logged in
sync time
starting count 1
colvals: 1001
count 1 took: 3.41200017929 seconds
starting count 2
lastrow: 1001
count 2 took: 531.482000113 seconds
这是新旧对比:
def findLastRow():
global spreadsheet
global datastartrow
global datastartcolumn
t0 = time.time()
print 'starting count 1'
colvals = worksheet.col_values(1)
t1 = time.time()
print 'colvals: ', len(colvals)
print 'count 1 took: ', str(t1 - t0) + ' seconds'
# return len(colvals)
t0 = time.time()
print 'starting count 2'
lastrow = datastartrow
while(True):
val = worksheet.cell(lastrow, datastartrow).value
if val == '':
lastrow -= 1
break
lastrow += 1
print 'lastrow: ', lastrow
t1 = time.time()
print 'count 2 took: ', str(t1 - t0) + ' seconds'
return lastrow