Deleting Data Woefully Slow
Brian Yennie
briany at qldlearning.com
Thu Mar 25 01:24:40 EDT 2010
Testing semantics aside, I definitely agree with your conclusions. Repeat for each performs awfully well for text operations if you can encapsulate your logic in a single pass.
One additional method to consider... have you tried using split / combine to turn the data into an array, something like (pseudo-code):
split myData
...
delete myData[5]
delete myData[9]
...
combine myData
I have a feeling the overhead of doing both a split and combine will still lose most times versus "repeat for each", but haven't tried it myself.
> Mark and Brian,
>
> Thanks for your comments.
>
> Mark you are absolutely right about tests 9, 10 and 11 - it's the problem of
> taking my real life situation and simplifying for the List. I've revised the
> script and this time TESTED the output to confirm the last 3 create
> identical data.
>
> No change, it's still quicker to take a HUGE set of data and recreate a
> slightly smaller version of it, than it is to just delete a small amount
> from it - although it only applies if you can use 'repeat for each' to
> create your new data.
>
> Brian, whilst put line 1 to -2 might be OK if all you want to do is delete
> the last line, and I accept I used it in my 'simple' examples, the last
> three Tests are more real life, where the line to delete is imbedded
> 'somewhere' in the data. Interestingly though you again prove the point that
> 'putting data' in Rev is much faster than 'delete' data.
>
> REVISED test results I got on a MBP 2.16GHz, 2 GB RAM, OS X.6.2, Rev Studio
> 4.0.0 Build 950
>
> **repeat for each**
> put after = 2 ms
> delete line -1 = 327 ms
> put before = 10 ms
> delete line 1 = 9 ms
> **repeat with x = **
> put after = 158 ms
> delete line -1 = 322 ms
> put before = 196 ms
> delete line 1 = 10 ms
> Create 90% - repeat for each = 2 ms
> Create 90% - repeat with x = 288 ms
> Delete 10% = 199 ms
>
> 50000 repeats
> **repeat for each**
> put after = 19 ms
> delete line -1 = 35491 ms
> put before = 951 ms
> delete line 1 = 934 ms
> **repeat with x = **
> put after = 18528 ms
> delete line -1 = 35208 ms
> put before = 18872 ms
> delete line 1 = 929 ms
> Create 90% - repeat for each = 26 ms
> Create 90% - repeat with x = 33341 ms
> Delete 10% = 19790 ms
>
> The REVISION 3 script I used:
>
> on mouseUp
> repeat 50000 times
> put random (9) & cr after tData
> end repeat
> --test 1
> put the millisec into tStart
> repeat for each line tLine in tData
> put tLine & cr after tData1
> end repeat
> put the millisec into tEnd
> put tEnd - tStart into tTotal1
> --test 2
> put the millisec into tStart
> repeat for each line tLine in tData
> delete line -1 of tData1
> end repeat
> put the millisec into tEnd
> put tEnd - tStart into tTotal2
> --test 3
> put the millisec into tStart
> repeat for each line tLine in tData
> put tLine & cr before tData1
> end repeat
> put the millisec into tEnd
> put tEnd - tStart into tTotal3
> --test 4
> put the millisec into tStart
> repeat for each line tLine in tData
> delete line 1 of tData1
> end repeat
> put the millisec into tEnd
> put tEnd - tStart into tTotal4
> --test 5
> put the millisec into tStart
> repeat with tCounter = 1 to the number of lines of tData
> put line tCounter of tData & cr after tData1
> end repeat
> put the millisec into tEnd
> put tEnd - tStart into tTotal5
> --test 6 ***REVISED***
> put the millisec into tStart
> repeat with tCounter = 1 to the number of lines of tData
> delete line -1 of tData1
> end repeat
> put the millisec into tEnd
> put tEnd - tStart into tTotal6
> --test 7
> put the millisec into tStart
> repeat with tCounter = 1 to the number of lines of tData
> put line tCounter of tData & cr before tData1
> end repeat
> put the millisec into tEnd
> put tEnd - tStart into tTotal7
> --test 8
> put the millisec into tStart
> repeat with tCounter = 1 to the number of lines of tData
> delete line 1 of tData1
> end repeat
> put the millisec into tEnd
> put tEnd - tStart into tTotal8
> --test 9 ***REVISED***
> put the millisec into tStart
> repeat for each line tLine in tData
> if NOT(tLIne contains 1) then
> put tLine & cr after tData1
> end if
> end repeat
> put the millisec into tEnd
> put tEnd - tStart into tTotal9
> --test 10 ***REVISED***
> put the millisec into tStart
> repeat with tCounter = 1 to the number of lines of tData
> if NOT(line tCounter of tData contains 1) then
> put line tCounter of tData & cr after tData2
> end if
> end repeat
> put the millisec into tEnd
> put tEnd - tStart into tTotal10
> --test 11 ***REVISED***
> put tData into tData3
> put the millisec into tStart
> repeat with tCounter = the number of lines of tData down to 1
> if (line tCounter of tData contains 1) then
> delete line tCounter of tData3
> end if
> end repeat
> put the millisec into tEnd
> put tEnd - tStart into tTotal11
>
> put "**repeat for each**" & cr into msg
> put "put after = " & tTotal1 & " ms" & cr after msg
> put "delete line -1 = " & tTotal2 & " ms" & cr after msg
> put "put before = " & tTotal3 & " ms" & cr after msg
> put "delete line 1 = " & tTotal4 & " ms" & cr after msg
> put "**repeat with x = **" & cr after msg
> put "put after = " & tTotal5 & " ms" & cr after msg
> put "delete line -1 = " & tTotal6 & " ms" & cr after msg
> put "put before = " & tTotal7 & " ms" & cr after msg
> put "delete line 1 = " & tTotal8 & " ms" & cr after msg
> put "Create 90% - repeat for each = " & tTotal9 & " ms" & cr after msg
> put "Create 90% - repeat with x = " & tTotal10 & " ms" & cr after msg
> put "Delete 10% = " & tTotal11 & " ms" & cr after msg
> end mouseUp
More information about the use-livecode
mailing list