Commit 02d3dc78 authored by eckhart's avatar eckhart

- added profiling subdirectory

parent b60f716d
This source diff could not be displayed because it is too large. You can view the blob instead.
#!/usr/bin/env python3
"""test_syntaxtree.py - profiling of syntaxtree-module of DHParser
Author: Eckhart Arnold <arnold@badw.de>
Copyright 2017 Bavarian Academy of Sciences and Humanities
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import os
import sys
scriptpath = os.path.dirname(__file__) or '.'
from DHParser.syntaxtree import parse_xml
def cpu_profile(func, repetitions=1):
"""Profile the function `func`.
"""
import cProfile
import pstats
profile = cProfile.Profile()
profile.enable()
success = True
for _ in range(repetitions):
success = func()
if not success:
break
profile.disable()
# after your program ends
stats = pstats.Stats(profile)
stats.strip_dirs()
stats.sort_stats('time').print_stats(80)
return success
def profile_serializing():
with open(os.path.join(scriptpath, 'data', 'inferus.ausgabe.xml')) as f:
data = f.read()
tree = parse_xml(data)
success = cpu_profile(tree.as_xml, 100)
if __name__ == "__main__":
profile_serializing()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment