Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
compare get count vs search cursor perf
#!/usr/bin/env python
# * coding: utf8 *
'''
args.py
A module that contains sample code to get params
'''
import arcpy
import timeit
roads = 'C:\\Projects\\Data\\transportation.gdb\\Roads'
def get_count():
return int(arcpy.GetCount_management('C:\\Projects\\Data\\transportation.gdb\\Roads').getOutput(0))
def cursor_count():
return len([row for row in arcpy.da.SearchCursor('C:\\Projects\\Data\\transportation.gdb\\Roads', ['*'])])
if __name__ == '__main__':
print(get_count())
print(cursor_count())
print('gp tool: ' + str(timeit.timeit("int(arcpy.GetCount_management('test.gdb\\\\Roads').getOutput(0))", setup="import arcpy", number=5)))
print('cursor: ' + str(timeit.timeit("len([row for row in arcpy.da.SearchCursor('test.gdb\\\\Roads', ['*'])])", setup="import arcpy", number=5)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.