Reverse a list

Mike Kerner MikeKerner at roadrunner.com
Fri Feb 13 16:04:01 EST 2015


NO!  SORRY!  My mixup in the last post - the REPEAT FOR is faster (repeat
for each line...)

On Fri, Feb 13, 2015 at 4:02 PM, Mike Kerner <MikeKerner at roadrunner.com>
wrote:

> No, no, it isn't 100,000 lines, it's only 10,000 lines.  0.129 vs 39.0.
>
> So then, just for the heck of it, because if we do the "repeat for", we
> gain some additional information (the line number we're on), I added "put 0
> into i" before the loop and then "add 1 to i" inside the loop, at the top.
> We get... 0.135 seconds.
>
> On Fri, Feb 13, 2015 at 3:49 PM, Peter Haworth <pete at lcsql.com> wrote:
>
>> Hi Mike,
>> Glad you figured out the reason for the speed difference.
>>
>> Not sure if there's a single thread anywhere that talks about repeat loops
>> but "repeat with" can be orders of magnitude faster than "repeat for" as
>> you've discovered.  In this case there were about 100k lines in the data
>> and I think I'm right in saying that the time taken to execute a repeat
>> with loop is directly related to the number of lines being processed.
>>
>>
>>
>> On Fri Feb 13 2015 at 12:41:14 PM Mike Kerner <MikeKerner at roadrunner.com>
>> wrote:
>>
>> > I must have missed a thread, somewhere.  That would be the thread on
>> how LC
>> > handles loops.
>> >
>> > To recap, doing this sort using an sqlite database (insert the values
>> into
>> > a table, then sort the table), was taking me almost 40 seconds.  Then
>> Pete
>> > chimed in and had it working in a couple hundred milliseconds.
>> >
>> > The difference?  Pete was using a loop of the form
>> > repeat for each line tLine in theData
>> >
>> > and I was doing a
>> > repeat with i = 1 to the number of lines in tData
>> >
>> >
>> > So, is there some more in-depth discussion of loop forms in LC,
>> somewhere?
>> > I learned something new, today, because 300x faster is a little bit
>> > important.
>> >
>> > On Thu, Feb 12, 2015 at 9:35 PM, Kay C Lan <lan.kc.macmail at gmail.com>
>> > wrote:
>> >
>> > > On Fri, Feb 13, 2015 at 3:04 AM, J. Landman Gay <
>> > jacque at hyperactivesw.com>
>> > > wrote:
>> > >
>> > > > On 2/12/2015 12:54 PM, Peter Haworth wrote:
>> > > >
>> > > >>
>> > > >>>  I haven't run any of the LC scripts to do this but if that's
>> true,
>> > > then
>> > > >> they don't achieve the original objective of reversing the list.
>> > > >>
>> > > >
>> > > > I don't think it's true. Using LC scripts, the first and last lines
>> > will
>> > > > be terminated by a CR and the line count won't change. The first and
>> > last
>> > > > lines will have no values but are still terminated by a CR, which is
>> > what
>> > > > determines the count.
>> > > >
>> > >
>> > > Jacques right. I should have actually run the scripts rather than just
>> > > doing it mentally. Because they all add a terminating CR then all is
>> > good.
>> > >
>> > > Apologies for confusing the matter.
>> > > _______________________________________________
>> > > use-livecode mailing list
>> > > use-livecode at lists.runrev.com
>> > > Please visit this url to subscribe, unsubscribe and manage your
>> > > subscription preferences:
>> > > http://lists.runrev.com/mailman/listinfo/use-livecode
>> > >
>> >
>> >
>> >
>> > --
>> > On the first day, God created the heavens and the Earth
>> > On the second day, God created the oceans.
>> > On the third day, God put the animals on hold for a few hours,
>> >    and did a little diving.
>> > And God said, "This is good."
>> > _______________________________________________
>> > use-livecode mailing list
>> > use-livecode at lists.runrev.com
>> > Please visit this url to subscribe, unsubscribe and manage your
>> > subscription preferences:
>> > http://lists.runrev.com/mailman/listinfo/use-livecode
>> >
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>
>
>
> --
> On the first day, God created the heavens and the Earth
> On the second day, God created the oceans.
> On the third day, God put the animals on hold for a few hours,
>    and did a little diving.
> And God said, "This is good."
>



-- 
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
   and did a little diving.
And God said, "This is good."



More information about the use-livecode mailing list