oskusalerma/trelby — pull request #131 by anilgulecha (2012-03-05 09:33:04+00:00)
Title: Undo3

Added performance/memory metrics code in latest commit. I used the ~115 page terminator 2 script.

I wrote a little until the 100 sized undo buffer was close to full. Here's the output from cmdTest, at a couple of different stages (16/100, and 89/100)

Lines in screenplay: 5181
Current size/capacity of undo: 16/100
Lines in undobuffer: 5213

Lines in screenplay: 5190
Current size/capacity of undo: 89/100
Lines in undobuffer: 5365

To understand these numbers: Undo buffer maintains diffs, which is usually 1-2 line object per undo, and a top, which is a copy of the entire screenplay. With a big enough script, the memory required is simply double the number of lines + undobuffer length.

-----------

I added performance tests to cmdSpeedTest as well. Results with same t2 script (115 pages)

--------------------
0.00307 seconds per testAddRemoveChar
0.04633 seconds per testDeepcopy
0.01295 seconds per testPaginate
0.13811 seconds per testReformatAll
0.01937 seconds per testScreenplayDiff
0.00003 seconds per testScreenplayDiffFast
0.03314 seconds per testUpdateScreen
--------------------

Note that in the most common cases when undo points are created (typing in words, undo points created with space, etc), testScreenplayDiffFast is what's called.. it's very fast because it constant time algorithm -- assumes a single line change around the line number we provide.

------

I realise the patch is broken into three commits. If you want I can merge all of them into one and re-push.