-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strange slowdown of parser function #220
Comments
The files to reproduce this issue can be found here. |
@PhilippRue To identify performance problems I often use the
You select functions you want to profile by adding @profile #Nothing has to be imported
def foo():
... And execute an example script with |
One thing I would be suspicious of is the line tmpval = tmptxt.pop(itmp) since |
Thanks, I'll give the |
So why the combination of reading and extracting values is much slower than the separated functions I don't know but I tried using generators in def search_string(searchkey, txt):
for index, line in enumerate(txt):
if searchkey in line:
yield index, line The the search function looks like this def search(tmptxt, searchstring, splitinfo, replacepair=None, debug=False):
res = []
while itmp, tmpval in search_string(searchstring, tmptxt):
if debug:
print(('in parse_array_float (itmp, searchstring, outfile):', itmp, searchstring, outfile))
if itmp >= 0:
if replacepair is not None:
tmpval = tmpval.replace(replacepair[0], replacepair[1])
if splitinfo[0] == 1:
tmpval = float(tmpval.split(splitinfo[1])[splitinfo[2]])
elif splitinfo[0] == 2:
tmpval = float(tmpval.split(splitinfo[1])[splitinfo[2]].split()[splitinfo[3]])
else:
raise ValueError('splitinfo[0] has to be either 1 or 2')
res.append(tmpval)
res = array(res)
return res |
Oh wait I think I know why the separation is much faster. In search the |
Ah, yes that makes sense. Thanks a lot for your help. We'll use your fix using generators :) |
A function that is used in the KKR parsers to search output files slows down for some reason if the output file is larger. This can be seen in the attached screenshot where the search alone is completed in 2ms, the reading of the outputfile alone also takes 2ms but when both steps are combined the parser takes 300ms.
The text was updated successfully, but these errors were encountered: