I have the following two pieces of code:
First, in SQL:
self.cursor.execute('SELECT apple_id FROM main_catalog WHERE apple_id=%s', apple_id)
if self.cursor.fetchone():
print '##'
Next, in Django:
if Catalog.objects.filter(apple_id=apple_id).exists():
print '>>>'
Doing it the first way is about 4x faster than the second way in a loop of 100k entries. What accounts for Django being so much slower?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…