On Thu, May 31, 2018 at 4:43 PM, Edward K. Ream wrote:
The test script I use limits the number of redraws to 1000, which should be
> plenty good enough. That script takes about 6 seconds on my machine.
>
> It's tricky to get real stats for the entire run, because most of the
> script runs at Tk idle time. I'll report back when I find a solution.
>
I changed the test script so it runs the code all at once, without waiting
for idle time. So the script doesn't draw anything until the very end, but
I don't care about the Tk stuff, only Vitalije's code:
def traverse_speed(x):
'''Traverse the entire tree.'''
g.cls()
if profile_redraw:
cProfile.runctx('traverse_speed_helper()',
globals(),
locals(),
'profile_stats', # 'profile-%s.out' % process_name
)
print('===== starting profile_stats')
p = pstats.Stats('profile_stats')
p.sort_stats('ncalls').print_stats(100)
# p.strip_dirs().
# .print_stats('leoDataModel.py', 50)
else:
traverse_speed_helper()
def traverse_speed_helper():
ltm.selectedPosition = ltm.positions[1]
ltm.expanded.clear()
ltm.invalidate_visual()
draw_tree(tree, ltm)
def tf(i):
if profile_redraw:
n_positions = len(ltm.positions)
n = min(1000, n_positions)
for i in range(n):
# From alt_right:
bw = G.body
gnx = ltm.select_node_right()
if gnx:
body = ltm.attrs[gnx][1]
bw.replace('1.0', 'end', body)
draw_tree(tree, ltm)
print('===== writing profile_stats')
p = pstats.Stats('profile_stats')
p.strip_dirs().sort_stats('tottime').print_stats(50)
# .print_stats('leoDataModel.py', 50)
else:
alt_right(None)
if i < 500 and i < n_positions:
tree.after_idle(tf, i + 1)
dt = datetime.datetime.utcnow() - t1
t = dt.seconds + 1e-6*dt.microseconds
G.log.insert('end -1 ch', '%s iterations in %6.2f sec\n'%(n,t))
t1 = datetime.datetime.utcnow()
tf(1)
G.app.bind_all('<Shift-F10>', traverse_speed)
Here are the edited results:
TotTime:
ncalls tottime percall cumtime percall filename:lineno(function)
2001 0.162 0.000 1.995 0.001 miniTkLeo.py:302(draw_loop)
30005 0.074 0.000 0.091 0.000 leoDataModel.py:482(
display_items)
----------
159149 1.225 0.000 1.751 0.000 {method 'call' of
'_tkinter.tkapp' objects}
64080 0.118 0.000 0.174 0.000 tkinter\__init__.py:1309(
_options)
64062 0.108 0.000 1.065 0.000 tkinter\__init__.py:1460(
_configure)
NCalls:
ncalls tottime percall cumtime percall filename:lineno(function)
30005 0.074 0.000 0.091 0.000 leoDataModel.py:482(
display_items)
4001 0.002 0.000 0.026 0.000 leoDataModel.py:312(
selectedIndex)
3000 0.004 0.000 1.187 0.001 miniTkLeo.py:452(proxycmd)
2001 0.162 0.000 2.006 0.001 miniTkLeo.py:302(draw_loop)
2001 0.008 0.000 2.045 0.001 miniTkLeo.py:290(draw_tree)
2001 0.003 0.000 0.012 0.000 miniTkLeo.py:469(rows_count)
----------
348928 0.054 0.000 0.054 0.000 {built-in method builtins.
isinstance}
159149 1.234 0.000 1.764 0.000 {method 'call' of
'_tkinter.tkapp' objects}
128160 0.026 0.000 0.026 0.000 {built-in method _tkinter.
_flatten}
128142 0.099 0.000 0.155 0.000 tkinter\__init__.py:93(
_cnfmerge)
92088 0.008 0.000 0.008 0.000 {built-in method builtins.
callable}
86022 0.032 0.000 0.032 0.000 {method 'splitlist' of
'_tkinter.tkapp' objects}
84021 0.094 0.000 0.633 0.000 tkinter\__init__.py:2458(
coords)
84021 0.013 0.000 0.013 0.000 tkinter\__init__.py:2461(<
listcomp>)
65191 0.008 0.000 0.008 0.000 {method 'items' of 'dict'
objects}
64098 0.015 0.000 0.015 0.000 {method 'update' of 'dict'
objects}
64080 0.118 0.000 0.175 0.000 tkinter\__init__.py:1309(
_options)
64062 0.033 0.000 1.105 0.000 tkinter\__init__.py:2565(
itemconfigure)
64062 0.111 0.000 1.072 0.000 tkinter\__init__.py:1460(
_configure)
63854 0.007 0.000 0.007 0.000 {built-in method builtins.len}
Only the items "above the line" refer to Vitalije's code. It's remarkable
how few functions/methods are involved, and how little time they take. The
next step will be to study all these routines in detail.
Edward
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.