I always wanted to compare these two functions to see which won, and spoiler alert, it's system.tag.browse
by more than an order of magnitude! At least for my very small site and test case...
sampling execution count = 50
system.tag.browse
= 15ms
system.tag.query
= 206ms
Code
provider = 'default'
query = {
"options": {
"includeUdtMembers": True,
"includeUdtDefinitions": False
},
"condition": {
"tagType": "UdtInstance",
"attributes": {
"values": [],
"requireAll": True
},
"properties": {
"op": "Or",
"conditions": [
{
"op": "And",
"conditions": [
{
"prop": "typeId",
"comp": "Equal",
"value": "<Specific UDT Type>"
}
]
}
]
}
},
"returnProperties": []
}
tests = 50
from java.lang.System import nanoTime as nt
def average_execution_time(func, num_executions):
total_execution_time = 0
for _ in range(num_executions):
start_time = nt()
func() # Call the function passed as an argument
end_time = nt()
execution_time = end_time - start_time
total_execution_time += execution_time
# Calculate the average execution time
average_time = total_execution_time / num_executions
return average_time
def q():
system.tag.query(provider, query)
def browse():
system.tag.browse('[default]<Base Area folder to exclude _types_ folder>', filter={'recursive': True, 'tagType': 'UdtInstance', 'typeId': "<Specific UDT Type>"})
average_execution_time(q, 50)/1000000
average_execution_time(browse, 50)/1000000
Default Tag Provider Summary
Code: Ignition Tag Count in a project - #2 by nminchin
Tag summary for provider "default"
tagType: {'UdtInstance': 122, 'Folder': 126, 'AtomicTag': 1242}
valueSource: {'memory': 234, 'opc': 802, 'reference': 2, 'expr': 195, 'db': 9}
dataType: {'Float4': 2, 'Int2': 3, 'DataSet': 55, 'Float8': 206, 'Int4': 415, 'String': 47, 'Int8': 61, 'Document': 1, 'Boolean': 452}
tagGroup: {'Default': 1354, 'Alarm Summary': 39, 'ConfigTags_CMDPLCReset': 73, 'Value Change Triggers': 24}
eventScripts: {'eventScripts': 78}
historyEnabled: {'False': 1490}