This was run out of the arcmap environment
Worded that wrong. out meaning not in arcmap. I just ran it from the command line:C:\Users\k\Desktop>c:\Python26\ArcGIS10.0\python.exe add_field_test.py
GDB time: 14.9272383107
SHP time: 0.505886972475
MEM time: 0.53527747266
I ran another test creating the feature classes for each type and still performance is terrible:from osgeo import ogr
import time
import arcview
import arcpy
gdb = "c:/data/temp.gdb/test_gdb"
shp = "c:/data/test_shp.shp"
mem = "in_memory/test"
ogr_shp = "c:/data/test_ogr.shp"
print("Creating feature classes...")
arcpy.CreateFeatureclass_management("c:/data/temp.gdb","test_gdb","POINT")
arcpy.CreateFeatureclass_management("c:/data","test_shp.shp","POINT")
arcpy.CreateFeatureclass_management("in_memory","test","POINT")
arcpy.CreateFeatureclass_management("c:/data","test_ogr.shp","POINT")
print("Feature classes created.")
n = 25
start = time.clock()
for i in range(n):
field = "FIELD_{0}".format(i)
arcpy.AddField_management(gdb,field,"DOUBLE")
t = time.clock() - start
gt = t
print("GDB time: {0}({1} sec per call)".format(t,t / n))
start = time.clock()
for i in range(n):
field = "FIELD_{0}".format(i)
arcpy.AddField_management(shp,field,"DOUBLE")
t = time.clock() - start
st = t
print("SHP time: {0}({1} sec per call)".format(t,t / n))
start = time.clock()
for i in range(n):
field = "FIELD_{0}".format(i)
arcpy.AddField_management(mem,field,"DOUBLE")
t = time.clock() - start
print("MEM time: {0}({1} sec per call)".format(t,t / n))
start = time.clock()
ds = ogr.Open(ogr_shp, 1)
lyr = ds.GetLayer()
for i in range(n):
field = "FIELD_{0}".format(i)
field_defn = ogr.FieldDefn(field,ogr.OFTReal)
lyr.CreateField(ogr.FieldDefn(field,ogr.OFTReal))
ds.Destroy()
t = time.clock() - start
print("OGR time: {0}({1} sec per call)".format(t,t / n))
print("Deleting feature classes...")
arcpy.Delete_management(gdb)
arcpy.Delete_management(shp)
arcpy.Delete_management(mem)
arcpy.Delete_management(ogr_shp)
print("Feature classes deleted.")
print("AddField is on shp is {0} times faster than on gdb".format(gt/st))
ogr is a spatial features access library with python bindings. Results are the same:C:\Users\k\Desktop>c:\Python26\ArcGIS10.0\python.exe add_field_test.py
Creating feature classes...
Feature classes created.
GDB time: 15.0151810344(0.600607241376 sec per call)
SHP time: 0.521969915836(0.0208787966335 sec per call)
MEM time: 0.550496636539(0.0220198654616 sec per call)
OGR time: 0.657494203585(0.0262997681434 sec per call)
Deleting feature classes...
Feature classes deleted.
AddField on shp is 28.7663725032 times faster than on gdb
Are you getting better performance? Can anyone post times for a call to AddField on a simple gdb?