Speed testing: Fastest search method

FlexibleLearning.com admin at FlexibleLearning.com
Sun Aug 31 13:57:17 EDT 2014


>From David Epstein

Q1. Not that I know of.
Q2. Of course it does, but the same condition is in place in all three
tests. And the data has to come from somewhere.
Q2. This 'repeat for each' rule refers to not modifying whatever 'each'
refers to. In this case, 'each' is a line and the number of lines in
unchanged so I am not changing the internal line pointers set up by the
engine at the start.

> 3 questions:
> 
> 1. Is there a good way to determine ahead of time whether memory is an
> issue? When I start the handler I can find out how big tVar is, but how do
I
> find out how much memory is available?
> 
> 2. Does this step in all 3 handlers --
> put fld "Data" into tVar
> -- itself use up memory? If fld "Data" is occupying a gigabyte of RAM,
does
> writing it to tVar use another gigabyte?
> 
> 3. Method #2 appears to me to violate the rule against modifying the
variable
> to which you are applying "repeat for each":
> #2:
> on mouseUp
> set the cursor to watch
> put the long seconds into tStart
> put fld "data" into tVar
> repeat for each line L in tVar
> add 1 to x
> if L="" then
> put "" into line x of tVar -- RIGHT HERE, WE'RE MODIFYING tVar!
> end if
> end repeat
> put tVar into fld "output"
> put the long seconds - tStart into fld "timer2"
> end mouseUp
> 
> Have I misunderstood that rule?
> 
> Many thanks.
> 
> David Epstein



From: Mike Bonner

Correct. My typo by omission.

> Method 2 doesn't have the filter, I am guessing the lack is a typo?  



From: Peter Haworth

1. Speed difference: 'for each' does not require the engine to repeatedly
(and increasingly) count from the start of the list each time, hence the
time saving.
2. Using a tCount variable: It would make no difference in performance, only
in terms of script explanation if necessary.

> I would expect method 1 to take longer but that's a huge difference. I
> wonder if this would speed it up:
> 
> Put the number of lines in tVar into tCount
> Repeat with x=tCount down to 1
> 
> Pete
 


From: jbv
This is a non-issue. If we wanted to remove blank lines, we would not use
any repeat structure but use 'filter tData without empty' instead. The
'empty lines condition' in the 3 tests is only a testing convenience that
stands for any conditional test.

> Have you tried the following method (condition is "line empty")  :
> on mouseUp
>    set the cursor to watch
>    put the long seconds into tStart
>    put fld "Data" into tVar
>    repeat while tVar contains (return & return)
>    	replace (return & return) with return in tVar
>    end repeat
>    put tVar into fld "output"
>    put the long seconds - tStart into fld "timer1"
> end mouseUp
> 
> jbv






More information about the use-livecode mailing list