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
|
elementpath~=1.3.0
|
||||||
lxml
|
lxml
|
||||||
memory_profiler
|
memory_profiler
|
||||||
|
matplotlib
|
||||||
pathlib2 # For Py27 tests on resources
|
pathlib2 # For Py27 tests on resources
|
||||||
Sphinx
|
Sphinx
|
||||||
sphinx_rtd_theme
|
sphinx_rtd_theme
|
||||||
|
|
|
@ -28,7 +28,7 @@ def test_choice_type(value):
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(add_help=True)
|
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:
|
Run memory tests:
|
||||||
1) Package import or schema build
|
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('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('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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,54 +69,62 @@ def build_schema(source):
|
||||||
|
|
||||||
|
|
||||||
@profile
|
@profile
|
||||||
def etree_parse(source):
|
def etree_parse(source, repeat=1):
|
||||||
xt = ElementTree.parse(source)
|
xt = ElementTree.parse(source)
|
||||||
for _ in xt.iter():
|
for _ in range(repeat):
|
||||||
pass
|
for _ in xt.iter():
|
||||||
|
|
||||||
|
|
||||||
@profile
|
|
||||||
def etree_full_iterparse(source):
|
|
||||||
context = ElementTree.iterparse(source, events=('start', 'end'))
|
|
||||||
for event, elem in context:
|
|
||||||
if event == 'start':
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@profile
|
@profile
|
||||||
def etree_emptied_iterparse(source):
|
def etree_full_iterparse(source, repeat=1):
|
||||||
context = ElementTree.iterparse(source, events=('start', 'end'))
|
for _ in range(repeat):
|
||||||
for event, elem in context:
|
context = ElementTree.iterparse(source, events=('start', 'end'))
|
||||||
if event == 'end':
|
for event, elem in context:
|
||||||
elem.clear()
|
if event == 'start':
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@profile
|
@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
|
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
|
@profile
|
||||||
def lazy_decode(source):
|
def lazy_decode(source, repeat=1):
|
||||||
decoder = xmlschema.XMLSchema.meta_schema if source.endswith('.xsd') else xmlschema
|
decoder = xmlschema.XMLSchema.meta_schema if source.endswith('.xsd') else xmlschema
|
||||||
for result in decoder.to_dict(xmlschema.XMLResource(source, lazy=True), path='*'):
|
for _ in range(repeat):
|
||||||
del result
|
for result in decoder.to_dict(xmlschema.XMLResource(source, lazy=True), path='*'):
|
||||||
|
del result
|
||||||
|
|
||||||
|
|
||||||
@profile
|
@profile
|
||||||
def validate(source):
|
def validate(source, repeat=1):
|
||||||
validator = xmlschema.XMLSchema.meta_schema if source.endswith('.xsd') else xmlschema
|
validator = xmlschema.XMLSchema.meta_schema if source.endswith('.xsd') else xmlschema
|
||||||
return validator.validate(source)
|
for _ in range(repeat):
|
||||||
|
validator.validate(source)
|
||||||
|
|
||||||
|
|
||||||
@profile
|
@profile
|
||||||
def lazy_validate(source):
|
def lazy_validate(source, repeat=1):
|
||||||
if source.endswith('.xsd'):
|
if source.endswith('.xsd'):
|
||||||
validator, path = xmlschema.XMLSchema.meta_schema, '*'
|
validator, path = xmlschema.XMLSchema.meta_schema, '*'
|
||||||
else:
|
else:
|
||||||
validator, path = xmlschema, None
|
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__':
|
if __name__ == '__main__':
|
||||||
|
@ -127,26 +136,26 @@ if __name__ == '__main__':
|
||||||
build_schema(args.xml_file)
|
build_schema(args.xml_file)
|
||||||
elif args.test_num == 2:
|
elif args.test_num == 2:
|
||||||
import xml.etree.ElementTree as ElementTree
|
import xml.etree.ElementTree as ElementTree
|
||||||
etree_parse(args.xml_file)
|
etree_parse(args.xml_file, args.repeat)
|
||||||
elif args.test_num == 3:
|
elif args.test_num == 3:
|
||||||
import xml.etree.ElementTree as ElementTree
|
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:
|
elif args.test_num == 4:
|
||||||
import xml.etree.ElementTree as ElementTree
|
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:
|
elif args.test_num == 5:
|
||||||
import xmlschema
|
import xmlschema
|
||||||
xmlschema.XMLSchema.meta_schema.build()
|
xmlschema.XMLSchema.meta_schema.build()
|
||||||
decode(args.xml_file)
|
decode(args.xml_file, args.repeat)
|
||||||
elif args.test_num == 6:
|
elif args.test_num == 6:
|
||||||
import xmlschema
|
import xmlschema
|
||||||
xmlschema.XMLSchema.meta_schema.build()
|
xmlschema.XMLSchema.meta_schema.build()
|
||||||
lazy_decode(args.xml_file)
|
lazy_decode(args.xml_file, args.repeat)
|
||||||
elif args.test_num == 7:
|
elif args.test_num == 7:
|
||||||
import xmlschema
|
import xmlschema
|
||||||
xmlschema.XMLSchema.meta_schema.build()
|
xmlschema.XMLSchema.meta_schema.build()
|
||||||
validate(args.xml_file)
|
validate(args.xml_file, args.repeat)
|
||||||
elif args.test_num == 8:
|
elif args.test_num == 8:
|
||||||
import xmlschema
|
import xmlschema
|
||||||
xmlschema.XMLSchema.meta_schema.build()
|
xmlschema.XMLSchema.meta_schema.build()
|
||||||
lazy_validate(args.xml_file)
|
lazy_validate(args.xml_file, args.repeat)
|
||||||
|
|
Loading…
Reference in New Issue