I hope google will accept the attachment containing scripts. I've started implementing some of the propositions discussed earlier in another thread.
First of all I think Leo should have a single function that will build an
outline from some iterable.
def build_tree(c, it):
'''
This function builds a tree of vnodes from the
iterable generating tuples of the following form:
(parent_gnx, gnx, childIndex, h, b, ua)
The tuples must be in the outline order.
Returns vnode instance that is a root of this tree.
'''
gnxDict = c.fileCommands.gnxDict
def getv(gnx, h, b, ua):
v = gnxDict.get(gnx)
if v is None:
v = leoNodes.VNode(c, gnx)
v._headString = h
v._bodyString = b
if ua:
v.unknownAttributes = ua
gnxDict[gnx] = v
return v
# root is handled first, before the loop
parent_gnx, gnx, childIndex, h, b, ua = next(it)
vparent = gnxDict.get(parent_gnx)
root = getv(gnx, h, b, ua)
vparent.children.insert(childIndex, root)
root.parents.append(vparent)
# now rest of the tuples
for parent_gnx, gnx, childIndex, h, b, ua in it:
vparent = gnxDict.get(parent_gnx)
v = getv(gnx, h, b, ua)
vparent.children.insert(childIndex, v)
v.parents.append(vparent)
return root
For any operation that need to build some sub-tree, it would be easier to
implement just an iterable which yields tuples and then call build_tree.
The build_tree should be tested and proved to work correctly. Then all
other commands just need to test generated tuples which won't have any bad
effect on the Leo's outline.
I have to go now. So, I'll write more later.
In the attached Leo document there are two python scripts:
1. makedemos.py - creates a zip file containing 1000 random Leo
documents
2. testdemos.py - tests roundtrip of each of these 1000 random
documents. Loads file, builds tree, then generates xml from the outline and
compares it with the input.
The testdemos.py contains three similar scripts. The test_1 uses Leo
c.fileCommands.putLeoFile to generate xml output. The test_2 uses new
functions to generate xml output but for each random file creates a
separate commander. Finally, test_3 reuses a single commander instance. For
each random file, this commander is reset.
Running testdemos.py on my computer gives the following output:
test_1 ( 10 files) - 4.891s ........ average:489.07ms
test_2 (1000 files) - 12.833s ........ average:12.83ms
test_3 (1000 files) - 2.216s ........ average: 2.22ms
1/2 ---> 38.11 times faster
1/3 ---> 220.71 times faster
Roundtrip xml->outline->xml using new reusable functions takes at least 38
times less time.
Vitalije
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/leo-editor/f96c2078-0b60-49a6-9146-36897135e7d9%40googlegroups.com.
issue-1598-experiments.leo
Description: Binary data
