[XML-SIG] speed question re DOM parsing
Juergen Hermann
Juergen Hermann" <jhe@webde-ag.de
Fri, 23 Jun 2000 12:18:22 +0200
On Fri, 23 Jun 2000 12:12:08 +0200, Juergen Hermann wrote:
>The result is obvious, and also what I expected.
Only I forgot about name lookup rules, so...
Length of testtext is 967
adding 27.935
stringio 24.717
stringio2 19.703
Length of testtext is 967
adding 27.583
stringio 24.43
stringio2 19.544
---%<----------------------------------
# Timings on char-wise string growing
import time, string, sys, cStringIO, array
testtext = open(sys.argv[0], "rt").read()
def timing(f, n, a):
print "%20s" % (f.__name__,),
r = range(n)
t1 = time.clock()
for i in r:
f(a); f(a); f(a); f(a); f(a); f(a); f(a); f(a); f(a); f(a)
t2 = time.clock()
print "\t", round(t2-t1, 3)
def adding(x):
result = ""
for ch in testtext:
result = result + ch
#print "adding(): len =", len(result)
def stringio(x):
chars = cStringIO.StringIO()
for ch in testtext:
chars.write(ch)
result = chars.getvalue()
#print "stringio(): len =", len()
def stringio2(x):
chars = cStringIO.StringIO()
push = chars.write
for ch in testtext:
push(ch)
result = chars.getvalue()
#print "stringio(): len =", len()
print "Length of testtext is", len(testtext)
n=1000
timing(adding, n, None)
timing(stringio, n, None)
timing(stringio2, n, None)