Created
June 6, 2017 15:56
-
-
Save steveoh/2b95d12dd23b786c6481231690c35d6b to your computer and use it in GitHub Desktop.
compare get count vs search cursor perf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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