Execution speed comparison of system.tag.query / browse --> browse wins

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}

6 Likes

Thanks for this writeup! Just including a note for others if they decide to test this as well, don't include a wildcard character (*) in the path (first argument) of the system.tag.browse() call, since it needs to be the starting folder for the search. This is in contrast to the "Tag Path" field of the Tag Report Tool, which does accept * as a wildcard.

If curious, my test results was roughly
.query = 522ms
.browse = 174ms

Note that my Ignition designer was remotely connected to my test site, which had over 20,000 tags. So, this is probably a "Your mileage may vary" situation, but interesting to explore more. I usually go with .query for the ease of setup, but I will have to give .browse a try again sometime.