Reverse a list

Peter Haworth pete at lcsql.com
Mon Feb 16 18:25:22 EST 2015


That's very interesting.  I've never used private since I had the
impression that the only thing it did was stop the handler from being
called outside of the script it appears in.

But it seems there is a performance benefit too.  Why would that be, I
wonder.  I understand that the engine only needs to look in the current
script for a private handler, but isn't that where the search for a handler
starts anyway?

On Mon Feb 16 2015 at 3:11:22 PM BNig <bernd.niggemann at uni-wh.de> wrote:

> Hi Jacque,
>
>
> J. Landman Gay wrote
> > This is getting to be just too much fun. I think Geoff was right, we
> > don't need to initialize sNum because we don't care if we go into
> > negative territory. And since the handler isn't actually using the value
> > of the line, we can omit passing it by removing "each". So it could be
> > even shorter/faster this way:
> >
> > local sNum
> > function reverseText @pList
> >     sort lines of pList numeric by reverseSort()
> >     return pList
> > end reverseText
> >
> > private function reverseSort
> >     subtract 1 from sNum
> >     return sNum
> > end reverseSort
> >
> > I'm not sure the private declaration is necessary, but it won't hurt. My
> > thinking is that the engine only looks for a private function in the
> > current script, but it also looks in the current script first when the
> > function isn't private. If the function is there, it seems that the
> > speed would be the same in either case. The engine would stop looking at
> > the same place.
> >
> > Passing the list with @ is a good addition.
> >
> > Then there is Alex's version which is a different animal.
> >
> >
> > On 2/16/2015 12:58 PM, BNig wrote:
> >> Hi Peter,
> >>
> >> you also might want to check your reverse algorithm on 7.x.x
> >>
> >> in my testing Jacque's initial post with little tweaks is as fast as
> your
> >> code and faster on 7.x.x (tested on 7.0.2 rc2) In my testing it took
> only
> >> 60% of the time compared to yours on 7.x.x
> >> Of course Alex Tweedly's ingenious inverse code leaves everything in the
> >> dust, except on 7.x.x.
> >> ----------------------------------------------------------------------
> >> on mouseUp
> >>     put field 1 into tData
> >>     put the milliseconds into t
> >>     get reverseText (tData)
> >>     put the milliseconds - t into field "fRes"
> >>     put it into field 1
> >> end mouseUp
> >>
> >> local sNum
> >> function reverseText @pList
> >>     put the number of lines in pList into sNum
> >>     sort lines of pList numeric by reverseSort(each)
> >>     return pList
> >> end reverseText
> >>
> >>   private function reverseSort
> >>     subtract 1 from sNum
> >>     return sNum
> >> end reverseSort
> >> --------------------------------------------------------
> >>
> >> private and @ help when the line count is high.
> >>
>
>
> funny, nobody likes "private"
>
> It save up to 20 % all else equal.
>
> On about 44000 lines 5 items on each line
>
> with private 86 ms, without 106 ms LC 6.7.2
>
> with private roughly 180 ms, without 200 ms on LC 7.0.2 rc2 (times vary
> much
> more on LC 7.0.2 rc2 than on LC 6.7.2
>
> Kind regards
> Bernd
>
>
>
> --
> View this message in context: http://runtime-revolution.
> 278305.n4.nabble.com/Reverse-a-list-tp4688611p4688925.html
> Sent from the Revolution - User mailing list archive at Nabble.com.
>
> _______________________________________________
> 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
>



More information about the Use-livecode mailing list