- Where Developers Learn, Share, & Build Careers


Given a large array of numbers where:

  [1, 2, 3 , 4 ...] = & gt; & Lt; Tag attrib = "1" /> & Lt; Tag attrib = "2" /> & Lt; Tag attrib = "3" /> & Lt; Tag attrib = "4" /> ...   

Which is more efficient / fast:

a) make them with scratch using the element ("name", attributes)

or

b) from fromstring (str) where str is the string representation of those tags in the instance

Update Test:

  to xml.etree.ElementTree import element, XML, tostring Elit: eroot ERR = Element ('Route') for .append (element ("tag", {"attrib": "antib"): time for import from time to time in estist = [xchange (1000) E for test_normal () Elit E for AIT test_list (): eroot = Element ('root') [eroot.append (element ("tag", {"attrib": "% s"% e})) ] Print "etree:% .6f"% timeit (test_normal, number = 1000) from xml.etree.cElementTree import element, XML, tostring, etc. print "L-cmp:% .6f"% timeit (test_list, number = 1000) ) Fromstring #from lxml.etree Import element, XML, tostring print "ctree:% .6f"% timeit (test_normal, number = 1000) print "c-cmp:% 6f"% timeit (test_list, number = 1000) def test_string (): Eroot = "& lt; Root & gt; "Tag = ['& lt; tag attrib ="% s "/> E.I.U.U.E.U.E.E.U.E. (tag) for EEE + '& lt; / root & gt;' Tree = fromstring (eroot) print "strng:% .6f"% timeit (test_string, number = 1000) etree: 13.302093 L-CMP: 12.276725 ctree: 5.482961 c-cmp: 5.692758 strng: 6.578780   

CeilementTree is the fastest version so I would say: do not use the string!! -)

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -