Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

performance of SearchCursor and da.SearchCursor

$
0
0
I set up a comparison between SearchCursor and da.SearchCursor, the code is like this:

Code:

import arcpy, time

shp = r"C:\Users\THINK\Desktop\python\Data\TOWNS.shp"

#da SearchCursor
sTime = time.clock()
rows = arcpy.da.SearchCursor(shp, ["TOWN", "TOTAL_SQMI"])
for row in rows:
    town = row[0]
    area = row[1]
    print ("The area of %s is %s sq miles."%(town, area)) 
del row, rows

eTime = time.clock()
tDiff = eTime - sTime
print "da SearchCursor uses %s seconds."%(tDiff)



#SearchCursor
sTime = time.clock()
rows = arcpy.SearchCursor(shp)
for row in rows:
    town = row.getValue("TOWN")
    area = row.getValue("TOTAL_SQMI")
    print ("The area of %s is %s sq miles."%(town, area))
del row, rows

eTime = time.clock()
tDiff = eTime - sTime
print "SearchCursor uses %s seconds."%(tDiff)

I assume da.SearchCursor will be faster but it took more than 2 seconds while SearchCursor finished in just 0.5 second.
Is there something wrong with the test?

Viewing all articles
Browse latest Browse all 2485

Trending Articles