Deleting Data Woefully Slow

Kay C Lan lan.kc.macmail at gmail.com
Thu Mar 25 03:51:44 EDT 2010


On Thu, Mar 25, 2010 at 2:18 PM, Mark Wieder <mwieder at ahsoftware.net> wrote:

>
> This is getting a bit off topic, but you can't prove the above. If you
> used a counter instead of a random number, I'd say you were accurate.
> But you're deliberately calling the random number generator, which has
> a finite chance of returning all ones.
>
> Actually were both a bit off topic as we're focusing on the wrong thing.
This simply comes down to the speed 'repeat for each' goes through every
line vs 'repeat with x ='. It actually matters very little if there is 1 hit
in a million or 999999, there is still a million tests carried out and
repeat for each will always do it faster than repeat with x =... I know
because I just did a test, See below.

Basically putting data is way faster than deleting no matter what the ratio.


> Is it possible to refactor your code to use something other than
> nested repeat loops? My guess from what you've posted so far is that
> there isn't, but I'm grasping at straws... I don't know what you're
> aiming at for an end result - could a filter command help out?
>
>
> The problem with filter is I'm working with blocks of lines of data and
whilst filter will catch the front line, it wont pick up the following lines
that also need to be deleted. :-(( But something Brian wrote has got me
thinking and testing. Instead of 'delete lines 12345 to 12347...' I'm
looking at put Lines 1 to 12344... & cr & lines 12348 to -1.... ' Fingers
crossed.

10000 repeats
Create 0.1% - repeat with x = 784 ms
Delete 99.9%  - delete line x = 1482 ms
Create 0.1% - repeat for each = 2 ms

10000 repeats
Create 99.9% - repeat with x = 1465 ms
Delete 0.1%  - delete line x = 732 ms
Create 99.9% - repeat for each = 5 ms

on mouseUp
   put 10 into tHowMany
   put tHowMany * 1000 into tRepeats
   repeat tHowMany times
      repeat with x = 1 to 999
         put 1 & cr after tData
      end repeat
      put "a" & cr after tData
   end repeat
   --Simply change contains "a" to contains "1"
   --to test the Create 0.1%, delete 99.9%
   --in the tests below

   --Test 1
   put the millisec into tStart
   repeat with tCounter = 1 to the number of lines of tData
      if NOT(line tCounter of tData contains "a") then
         put line tCounter of tData & cr after tData1
      end if
   end repeat
   put the millisec into tEnd
   put tEnd - tStart into tTotal1

   put empty into tCounter
   put tData into tData1
   --Test 2

   put the millisec into tStart
   repeat with tCounter = the number of lines of tData down to 1
      if (line tCounter of tData contains "a") then
         delete line tCounter of tData1
      end if
   end repeat
   put the millisec into tEnd
   put tEnd - tStart into tTotal2

   put empty into tCounter
   put empty into tData1

   --Test 3
   put the millisec into tStart
   repeat for each line tLine in tData
      if NOT(tLIne contains "a") then
         put tLine & cr after tData1
      end if
   end repeat
   put the millisec into tEnd
   put tEnd - tStart into tTotal3

   put tRepeats & " repeats" & cr into msg
   put "Create 99.9% - repeat with x = " & tTotal1 & " ms" & cr after msg
   put "Delete 0.1%  - delete line x = " & tTotal2 & " ms" & cr after msg
    put "Create 99.9% - repeat for each = " & tTotal3 & " ms" & cr after msg
end mouseUp



More information about the use-livecode mailing list