There are many lines of the form:
a = '<httpSample t="51" lt="51" ts="1478854873129" s="true" lb="Enter SHI" rc="200" rm="OK" tn="Sorting 1-21" dt="text" by="1749"/>' The task: to find a faster way to get the values of the attributes "t" and "lb" from the strings of the type "a" than the presented ones (I clarify that the main criterion is time, it should be less than in the options I have presented):
Not good (the number of attributes changes suddenly), but quickly (the number of attributes is constant):
def x(): b = a.split('"') xxx, yyy = b[1], b[9]Good, but 6 times longer
x():import xml.etree.cElementTree as ET def y(): tree = ET.fromstring(a) xxx = tree.attrib['t'] yyy = tree.attrib['lb']
You can use to check:
from timeit import timeit print timeit(x, number=3000000) print timeit(y, number=3000000)