1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
# dry runs
from xml.parsers import xmllib, sgmlop
import sys
import time, string
try:
FILE, VERBOSE = sys.argv[1], 2
except IndexError:
FILE, VERBOSE = "hamlet.xml", 1
BLOCK = 16384
print
print "test empty parsers on", FILE
print
t = time.clock()
b = 0
for i in range(1):
fp = open(FILE)
parser = sgmlop.XMLParser()
while 1:
data = fp.read(BLOCK)
if not data:
break
parser.feed(data)
b = b + len(data)
parser.close()
t1 = time.clock() - t
print "sgmlop", round(t1, 3), "seconds;",
print round(b / t1 / 1024, 2), "kbytes per second"
t = time.clock()
b = 0
for i in range(1):
fp = open(FILE)
parser = xmllib.FastXMLParser()
while 1:
data = fp.read(BLOCK)
if not data:
break
parser.feed(data)
b = b + len(data)
parser.close()
t2 = time.clock() - t
print "fast xmllib", round(t2, 3), "seconds;",
print round(b / t2 / 1024, 2), "kbytes per second"
t = time.clock()
b = 0
for i in range(1):
fp = open(FILE)
parser = xmllib.SlowXMLParser()
while 1:
data = fp.read(BLOCK)
if not data:
break
parser.feed(data)
b = b + len(data)
parser.close()
t3 = time.clock() - t
print "slow xmllib", round(t3, 3), "seconds;",
print round(b / t3 / 1024, 2), "kbytes per second"
print
print "sgmlop is", round(t3 / t1, 2), "times faster than slow xmllib"
|