Extend check_memory.py script
- Add an argument to repeat test N times - Add matplotlib to dev requirements
This commit is contained in:
parent
8dd5d193ba
commit
8db83477df
|
@ -5,6 +5,7 @@ coverage
|
|||
elementpath~=1.3.0
|
||||
lxml
|
||||
memory_profiler
|
||||
matplotlib
|
||||
pathlib2 # For Py27 tests on resources
|
||||
Sphinx
|
||||
sphinx_rtd_theme
|
||||
|
|
|
@ -28,7 +28,7 @@ def test_choice_type(value):
|
|||
|
||||
|
||||
parser = argparse.ArgumentParser(add_help=True)
|
||||
parser.usage = """%(prog)s TEST_NUM [XML_FILE]
|
||||
parser.usage = """%(prog)s TEST_NUM [XML_FILE [REPEAT]]
|
||||
|
||||
Run memory tests:
|
||||
1) Package import or schema build
|
||||
|
@ -44,6 +44,7 @@ Run memory tests:
|
|||
|
||||
parser.add_argument('test_num', metavar="TEST_NUM", type=test_choice_type, help="Test number to run")
|
||||
parser.add_argument('xml_file', metavar='XML_FILE', nargs='?', help='Input XML file')
|
||||
parser.add_argument('repeat', metavar='REPEAT', nargs='?', type=int, default=1, help='Repeat operation N times')
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
|
@ -68,54 +69,62 @@ def build_schema(source):
|
|||
|
||||
|
||||
@profile
|
||||
def etree_parse(source):
|
||||
def etree_parse(source, repeat=1):
|
||||
xt = ElementTree.parse(source)
|
||||
for _ in xt.iter():
|
||||
pass
|
||||
|
||||
|
||||
@profile
|
||||
def etree_full_iterparse(source):
|
||||
context = ElementTree.iterparse(source, events=('start', 'end'))
|
||||
for event, elem in context:
|
||||
if event == 'start':
|
||||
for _ in range(repeat):
|
||||
for _ in xt.iter():
|
||||
pass
|
||||
|
||||
|
||||
@profile
|
||||
def etree_emptied_iterparse(source):
|
||||
context = ElementTree.iterparse(source, events=('start', 'end'))
|
||||
for event, elem in context:
|
||||
if event == 'end':
|
||||
elem.clear()
|
||||
def etree_full_iterparse(source, repeat=1):
|
||||
for _ in range(repeat):
|
||||
context = ElementTree.iterparse(source, events=('start', 'end'))
|
||||
for event, elem in context:
|
||||
if event == 'start':
|
||||
pass
|
||||
|
||||
|
||||
@profile
|
||||
def decode(source):
|
||||
def etree_emptied_iterparse(source, repeat=1):
|
||||
for _ in range(repeat):
|
||||
context = ElementTree.iterparse(source, events=('start', 'end'))
|
||||
for event, elem in context:
|
||||
if event == 'end':
|
||||
elem.clear()
|
||||
|
||||
|
||||
@profile
|
||||
def decode(source, repeat=1):
|
||||
decoder = xmlschema.XMLSchema.meta_schema if source.endswith('.xsd') else xmlschema
|
||||
return decoder.to_dict(source)
|
||||
for _ in range(repeat):
|
||||
decoder.to_dict(source)
|
||||
|
||||
|
||||
@profile
|
||||
def lazy_decode(source):
|
||||
def lazy_decode(source, repeat=1):
|
||||
decoder = xmlschema.XMLSchema.meta_schema if source.endswith('.xsd') else xmlschema
|
||||
for result in decoder.to_dict(xmlschema.XMLResource(source, lazy=True), path='*'):
|
||||
del result
|
||||
for _ in range(repeat):
|
||||
for result in decoder.to_dict(xmlschema.XMLResource(source, lazy=True), path='*'):
|
||||
del result
|
||||
|
||||
|
||||
@profile
|
||||
def validate(source):
|
||||
def validate(source, repeat=1):
|
||||
validator = xmlschema.XMLSchema.meta_schema if source.endswith('.xsd') else xmlschema
|
||||
return validator.validate(source)
|
||||
for _ in range(repeat):
|
||||
validator.validate(source)
|
||||
|
||||
|
||||
@profile
|
||||
def lazy_validate(source):
|
||||
def lazy_validate(source, repeat=1):
|
||||
if source.endswith('.xsd'):
|
||||
validator, path = xmlschema.XMLSchema.meta_schema, '*'
|
||||
else:
|
||||
validator, path = xmlschema, None
|
||||
return validator.validate(xmlschema.XMLResource(source, lazy=True), path=path)
|
||||
|
||||
for _ in range(repeat):
|
||||
validator.validate(xmlschema.XMLResource(source, lazy=True), path=path)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -127,26 +136,26 @@ if __name__ == '__main__':
|
|||
build_schema(args.xml_file)
|
||||
elif args.test_num == 2:
|
||||
import xml.etree.ElementTree as ElementTree
|
||||
etree_parse(args.xml_file)
|
||||
etree_parse(args.xml_file, args.repeat)
|
||||
elif args.test_num == 3:
|
||||
import xml.etree.ElementTree as ElementTree
|
||||
etree_full_iterparse(args.xml_file)
|
||||
etree_full_iterparse(args.xml_file, args.repeat)
|
||||
elif args.test_num == 4:
|
||||
import xml.etree.ElementTree as ElementTree
|
||||
etree_emptied_iterparse(args.xml_file)
|
||||
etree_emptied_iterparse(args.xml_file, args.repeat)
|
||||
elif args.test_num == 5:
|
||||
import xmlschema
|
||||
xmlschema.XMLSchema.meta_schema.build()
|
||||
decode(args.xml_file)
|
||||
decode(args.xml_file, args.repeat)
|
||||
elif args.test_num == 6:
|
||||
import xmlschema
|
||||
xmlschema.XMLSchema.meta_schema.build()
|
||||
lazy_decode(args.xml_file)
|
||||
lazy_decode(args.xml_file, args.repeat)
|
||||
elif args.test_num == 7:
|
||||
import xmlschema
|
||||
xmlschema.XMLSchema.meta_schema.build()
|
||||
validate(args.xml_file)
|
||||
validate(args.xml_file, args.repeat)
|
||||
elif args.test_num == 8:
|
||||
import xmlschema
|
||||
xmlschema.XMLSchema.meta_schema.build()
|
||||
lazy_validate(args.xml_file)
|
||||
lazy_validate(args.xml_file, args.repeat)
|
||||
|
|
Loading…
Reference in New Issue