Estaba evaluando qué método era más rápido para contar el número de filas de una tabla, cuando ocurrió algo curioso:
import arcpy
import os
import time
test_tuple = ("path\to\connection", "feature_class_name")
fc = os.path.join(*test_tuple)
i = 0
while i < 3:
# Method 1
time.sleep(5)
start_time = time.clock()
count = int(arcpy.GetCount_management(fc).getOutput(0))
end_time = time.clock()
print("Method 1 ({count}) finished in {time} seconds".format(count=count, time=(end_time - start_time)))
print("The count was: {count}".format(count=count))
# Method 2
time.sleep(5) # Let the cpu/ram calm before proceeding!
start_time = time.clock()
query = """SELECT COUNT(*) FROM {}""".format(test_tuple[-1].upper())
execute_object = arcpy.ArcSDESQLExecute(test_tuple[0])
result = execute_object.execute(query)
count = int(result)
end_time = time.clock()
print("Method 2 ({count}) finished in {time} seconds".format(count=count, time=(end_time - start_time)))
print("The count was: {count}".format(count=count))
i += 1
Esto dio los siguientes resultados:
Method 1 finished in 5.018752999999999 seconds
The count was: 22645
Method 2 finished in 0.24905560000000015 seconds
The count was: 21473
Method 1 finished in 0.7440046999999996 seconds
The count was: 22645
Method 2 finished in 0.7023353000000014 seconds
The count was: 21473
Method 1 finished in 0.7402944999999974 seconds
The count was: 22645
Method 2 finished in 0.684015500000001 seconds
The count was: 21473
¿Por qué los recuentos son diferentes entre los dos métodos?