remove empty lines

Alex Tweedly alex at tweedly.net
Thu Aug 3 10:06:07 EDT 2006


Richard Gaskin wrote:

>
> Easier to script, yes, but note the result from running this script 
> which compares both methods:
>
>
> on mouseUp
>   put 1000 into N
>   put fld 1 into tData
>   --
>   --
>   -- 1. repeat for each
>   --
>   put the millisecs into t
>   repeat N
>     --
>     put empty into R1
>     repeat for each line tLine in tData
>       if tLine is not empty then
>         put tLine &cr after R1
>       end if
>     end repeat
>     delete last char of R1
>     --
>   end repeat
>   put the millisecs - t into t1
>   --
>   --
>   -- 2. filter:
>   --
>   put the millisecs into t
>   repeat N
>     --
>     put tData into R2
>     filter R2 without empty
>     --
>   end repeat
>   put the millisecs - t into t2
>   --
>   --
>   -- Result:
>   put t1 && t2
> end mouseUp
>
Results are very data dependent; I get anything from
  30  14
to
  67 104
for different input fields (i.e. 2:1 ratio in either direction).

>
> Did I write this wrong?
>
Perhaps. Method 2 above makes a copy of the data before filtering the 
copy - which may or may not be necessary in the real application 
context. If the original (unfiltered) value is no longer needed then you 
*may* be able to avoid the copy- which would change the results (though 
not by very much - small change compared to the data dependency variation).

> Seems most times I benchmark "repeat for each" with the well-optimized 
> "put after" I get results that hold up surprisingly well.
>
> I have another post in the works with some other interesting 
> benchmarks related to processing lists (things I learned on summer 
> vacation <g>)...
>
I'll buy you a dictionary some day, so you can read up on "vacation" :-)


-- 
Alex Tweedly       http://www.tweedly.net



-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.10.5/406 - Release Date: 02/08/2006




More information about the use-livecode mailing list