Reverse a list

classic Classic list List threaded Threaded
132 messages Options
1234 ... 7
Reply | Threaded
Open this post in threaded view
|

Reverse a list

J. Landman Gay
Just tinkering around on a lazy Sunday, and I thought I'd come up with a
neat way to reverse a list without using the traditional clunky method:

function reverseSort pList
   repeat for each line l in pList
     put l & cr before tList
   end repeat
   return tList
end reverseSort

One of the best things I learned from a past LC converence came from
Jerry Daniels who said "let the engine do it." It's almost always faster
and more efficient. With that in mind I wrote this:

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

function reverseSort pTxt
   subtract 1 from sNum
   return sNum && pTxt
end reverseSort

Works great and I was proud. Then I did some timing tests and found out
the two methods are very close to equivalent in timing, and on long
lists, the first way is actually faster.

So much for improving on LC's text chunking speed. Pah.

--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Reverse a list

Mike Bonner
Just curious.. How does this compare?

local scount
on mouseUp
   put the number of lines in field 1 + 1 into scount
   sort lines of field 1 by getCount()
end mouseUp

function getCount
   subtract 1 from sCount
   return sCount
end getCount

On Sun, Feb 8, 2015 at 2:52 PM, J. Landman Gay <[hidden email]>
wrote:

> Just tinkering around on a lazy Sunday, and I thought I'd come up with a
> neat way to reverse a list without using the traditional clunky method:
>
> function reverseSort pList
>   repeat for each line l in pList
>     put l & cr before tList
>   end repeat
>   return tList
> end reverseSort
>
> One of the best things I learned from a past LC converence came from Jerry
> Daniels who said "let the engine do it." It's almost always faster and more
> efficient. With that in mind I wrote this:
>
> 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
>
> function reverseSort pTxt
>   subtract 1 from sNum
>   return sNum && pTxt
> end reverseSort
>
> Works great and I was proud. Then I did some timing tests and found out
> the two methods are very close to equivalent in timing, and on long lists,
> the first way is actually faster.
>
> So much for improving on LC's text chunking speed. Pah.
>
> --
> Jacqueline Landman Gay         |     [hidden email]
> HyperActive Software           |     http://www.hyperactivesw.com
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Reverse a list

Mike Bonner
Oops, make sure the sort is numeric, which I forgot.

On Sun, Feb 8, 2015 at 3:09 PM, Mike Bonner <[hidden email]> wrote:

> Just curious.. How does this compare?
>
> local scount
> on mouseUp
>    put the number of lines in field 1 + 1 into scount
>    sort lines of field 1 by getCount()
> end mouseUp
>
> function getCount
>    subtract 1 from sCount
>    return sCount
> end getCount
>
> On Sun, Feb 8, 2015 at 2:52 PM, J. Landman Gay <[hidden email]>
> wrote:
>
>> Just tinkering around on a lazy Sunday, and I thought I'd come up with a
>> neat way to reverse a list without using the traditional clunky method:
>>
>> function reverseSort pList
>>   repeat for each line l in pList
>>     put l & cr before tList
>>   end repeat
>>   return tList
>> end reverseSort
>>
>> One of the best things I learned from a past LC converence came from
>> Jerry Daniels who said "let the engine do it." It's almost always faster
>> and more efficient. With that in mind I wrote this:
>>
>> 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
>>
>> function reverseSort pTxt
>>   subtract 1 from sNum
>>   return sNum && pTxt
>> end reverseSort
>>
>> Works great and I was proud. Then I did some timing tests and found out
>> the two methods are very close to equivalent in timing, and on long lists,
>> the first way is actually faster.
>>
>> So much for improving on LC's text chunking speed. Pah.
>>
>> --
>> Jacqueline Landman Gay         |     [hidden email]
>> HyperActive Software           |     http://www.hyperactivesw.com
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Reverse a list

Mike Bonner
Using numeric sort, 100k lines being reversed takes 126 millisec on my
system.

On Sun, Feb 8, 2015 at 3:13 PM, Mike Bonner <[hidden email]> wrote:

> Oops, make sure the sort is numeric, which I forgot.
>
> On Sun, Feb 8, 2015 at 3:09 PM, Mike Bonner <[hidden email]> wrote:
>
>> Just curious.. How does this compare?
>>
>> local scount
>> on mouseUp
>>    put the number of lines in field 1 + 1 into scount
>>    sort lines of field 1 by getCount()
>> end mouseUp
>>
>> function getCount
>>    subtract 1 from sCount
>>    return sCount
>> end getCount
>>
>> On Sun, Feb 8, 2015 at 2:52 PM, J. Landman Gay <[hidden email]>
>> wrote:
>>
>>> Just tinkering around on a lazy Sunday, and I thought I'd come up with a
>>> neat way to reverse a list without using the traditional clunky method:
>>>
>>> function reverseSort pList
>>>   repeat for each line l in pList
>>>     put l & cr before tList
>>>   end repeat
>>>   return tList
>>> end reverseSort
>>>
>>> One of the best things I learned from a past LC converence came from
>>> Jerry Daniels who said "let the engine do it." It's almost always faster
>>> and more efficient. With that in mind I wrote this:
>>>
>>> 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
>>>
>>> function reverseSort pTxt
>>>   subtract 1 from sNum
>>>   return sNum && pTxt
>>> end reverseSort
>>>
>>> Works great and I was proud. Then I did some timing tests and found out
>>> the two methods are very close to equivalent in timing, and on long lists,
>>> the first way is actually faster.
>>>
>>> So much for improving on LC's text chunking speed. Pah.
>>>
>>> --
>>> Jacqueline Landman Gay         |     [hidden email]
>>> HyperActive Software           |     http://www.hyperactivesw.com
>>>
>>> _______________________________________________
>>> use-livecode mailing list
>>> [hidden email]
>>> Please visit this url to subscribe, unsubscribe and manage your
>>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>>
>>
>>
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Reverse a list

Mike Bonner
doh. Same thing you did. *sigh* Except i'm not passing the actual text back
and forth since theres no point. Ignore me. :)

On Sun, Feb 8, 2015 at 3:15 PM, Mike Bonner <[hidden email]> wrote:

> Using numeric sort, 100k lines being reversed takes 126 millisec on my
> system.
>
> On Sun, Feb 8, 2015 at 3:13 PM, Mike Bonner <[hidden email]> wrote:
>
>> Oops, make sure the sort is numeric, which I forgot.
>>
>> On Sun, Feb 8, 2015 at 3:09 PM, Mike Bonner <[hidden email]> wrote:
>>
>>> Just curious.. How does this compare?
>>>
>>> local scount
>>> on mouseUp
>>>    put the number of lines in field 1 + 1 into scount
>>>    sort lines of field 1 by getCount()
>>> end mouseUp
>>>
>>> function getCount
>>>    subtract 1 from sCount
>>>    return sCount
>>> end getCount
>>>
>>> On Sun, Feb 8, 2015 at 2:52 PM, J. Landman Gay <[hidden email]
>>> > wrote:
>>>
>>>> Just tinkering around on a lazy Sunday, and I thought I'd come up with
>>>> a neat way to reverse a list without using the traditional clunky method:
>>>>
>>>> function reverseSort pList
>>>>   repeat for each line l in pList
>>>>     put l & cr before tList
>>>>   end repeat
>>>>   return tList
>>>> end reverseSort
>>>>
>>>> One of the best things I learned from a past LC converence came from
>>>> Jerry Daniels who said "let the engine do it." It's almost always faster
>>>> and more efficient. With that in mind I wrote this:
>>>>
>>>> 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
>>>>
>>>> function reverseSort pTxt
>>>>   subtract 1 from sNum
>>>>   return sNum && pTxt
>>>> end reverseSort
>>>>
>>>> Works great and I was proud. Then I did some timing tests and found out
>>>> the two methods are very close to equivalent in timing, and on long lists,
>>>> the first way is actually faster.
>>>>
>>>> So much for improving on LC's text chunking speed. Pah.
>>>>
>>>> --
>>>> Jacqueline Landman Gay         |     [hidden email]
>>>> HyperActive Software           |     http://www.hyperactivesw.com
>>>>
>>>> _______________________________________________
>>>> use-livecode mailing list
>>>> [hidden email]
>>>> Please visit this url to subscribe, unsubscribe and manage your
>>>> subscription preferences:
>>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>>>
>>>
>>>
>>
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Reverse a list

Mike Bonner
Ok, last part and I'll shut up. On 100k lines, not passing the text itself
back and forth to the reverse sort saves about 50 millisec on my system.


On Sun, Feb 8, 2015 at 3:22 PM, Mike Bonner <[hidden email]> wrote:

> doh. Same thing you did. *sigh* Except i'm not passing the actual text
> back and forth since theres no point. Ignore me. :)
>
> On Sun, Feb 8, 2015 at 3:15 PM, Mike Bonner <[hidden email]> wrote:
>
>> Using numeric sort, 100k lines being reversed takes 126 millisec on my
>> system.
>>
>> On Sun, Feb 8, 2015 at 3:13 PM, Mike Bonner <[hidden email]> wrote:
>>
>>> Oops, make sure the sort is numeric, which I forgot.
>>>
>>> On Sun, Feb 8, 2015 at 3:09 PM, Mike Bonner <[hidden email]> wrote:
>>>
>>>> Just curious.. How does this compare?
>>>>
>>>> local scount
>>>> on mouseUp
>>>>    put the number of lines in field 1 + 1 into scount
>>>>    sort lines of field 1 by getCount()
>>>> end mouseUp
>>>>
>>>> function getCount
>>>>    subtract 1 from sCount
>>>>    return sCount
>>>> end getCount
>>>>
>>>> On Sun, Feb 8, 2015 at 2:52 PM, J. Landman Gay <
>>>> [hidden email]> wrote:
>>>>
>>>>> Just tinkering around on a lazy Sunday, and I thought I'd come up with
>>>>> a neat way to reverse a list without using the traditional clunky method:
>>>>>
>>>>> function reverseSort pList
>>>>>   repeat for each line l in pList
>>>>>     put l & cr before tList
>>>>>   end repeat
>>>>>   return tList
>>>>> end reverseSort
>>>>>
>>>>> One of the best things I learned from a past LC converence came from
>>>>> Jerry Daniels who said "let the engine do it." It's almost always faster
>>>>> and more efficient. With that in mind I wrote this:
>>>>>
>>>>> 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
>>>>>
>>>>> function reverseSort pTxt
>>>>>   subtract 1 from sNum
>>>>>   return sNum && pTxt
>>>>> end reverseSort
>>>>>
>>>>> Works great and I was proud. Then I did some timing tests and found
>>>>> out the two methods are very close to equivalent in timing, and on long
>>>>> lists, the first way is actually faster.
>>>>>
>>>>> So much for improving on LC's text chunking speed. Pah.
>>>>>
>>>>> --
>>>>> Jacqueline Landman Gay         |     [hidden email]
>>>>> HyperActive Software           |     http://www.hyperactivesw.com
>>>>>
>>>>> _______________________________________________
>>>>> use-livecode mailing list
>>>>> [hidden email]
>>>>> Please visit this url to subscribe, unsubscribe and manage your
>>>>> subscription preferences:
>>>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>>>>
>>>>
>>>>
>>>
>>
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Reverse a list

Alex Tweedly
In reply to this post by J. Landman Gay

Indeed. Jerry was (as usual) correct - if the engine can do it, then the
engine will normally be faster.

BUT sorting a list requires moving the data around quite a lot, AND
sorting something that actually reverses it can be a pathologically bad
case (e.g. if the engine uses any variant of quicksort())..

SO - take the original idea, and examine how it *might* be improved .....

The problem here is that "put ... before ..." requires all existing data
in the destination container to be moved (i.e. copied) to make space.

SO, instead, we can use "put ... into char x to y of ..." - since it
uses char indexing, it takes constant time (i.e. no scan, just directly
replace the chars.  I've attached my complete code so anyone can try it
easily - for my test data of approx 8000 lines, this takes 8 msecs,
versus 588 for the original version.

-- Alex.

on mouseup
    put fld "fldout" into tstart

    put tstart into ta
    repeat 200 times
       put tstart after ta
    end repeat
    put ta into tstart

    put the millisecs into t1
    put revers(ta) into tb
    put the millisecs - t1 & CR after msg

    put tstart into ta
    put the millisecs into t1
    put qrevers(ta) into tc
    put the millisecs - t1 & CR after msg

    if tb = tc then put "OK" after msg
end mouseup

function revers p
    repeat for each line l  in p
       put L &CR before t
    end repeat
    return t
end revers

function qrevers p
    put p into t
    put the number of chars in t into tlen
    repeat for each line l in p
       put the number of chars in l into tl
       put l & cr into char (tLen-tl) to tLen of t
       subtract (tl+1) from tLen
    end repeat
    return t
end qrevers


On 08/02/2015 21:52, J. Landman Gay wrote:

> Just tinkering around on a lazy Sunday, and I thought I'd come up with
> a neat way to reverse a list without using the traditional clunky method:
>
> function reverseSort pList
>   repeat for each line l in pList
>     put l & cr before tList
>   end repeat
>   return tList
> end reverseSort
>
> One of the best things I learned from a past LC converence came from
> Jerry Daniels who said "let the engine do it." It's almost always
> faster and more efficient. With that in mind I wrote this:
>
> 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
>
> function reverseSort pTxt
>   subtract 1 from sNum
>   return sNum && pTxt
> end reverseSort
>
> Works great and I was proud. Then I did some timing tests and found
> out the two methods are very close to equivalent in timing, and on
> long lists, the first way is actually faster.
>
> So much for improving on LC's text chunking speed. Pah.
>


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Reverse a list

Mike Bonner
Version 6.6.2, your "by position" method is by FAR the fastest 26 millisec
for 80k lines.  repeat takes almost 9 seconds.  The sort function method
not passing text back and forth,  takes 102 millisec which isn't slouchy by
any means.

Jump to version 7.0.1 and the by position method needs some major love.
The repeat method is almost twice as fast in 7, the sort without passing
the text method is within a few millisec of 6.6.2, and the by position
method is unusable at 21 seconds.  REALLY hope they get some optimization
going soon.

On Sun, Feb 8, 2015 at 3:37 PM, Alex Tweedly <[hidden email]> wrote:

>
> Indeed. Jerry was (as usual) correct - if the engine can do it, then the
> engine will normally be faster.
>
> BUT sorting a list requires moving the data around quite a lot, AND
> sorting something that actually reverses it can be a pathologically bad
> case (e.g. if the engine uses any variant of quicksort())..
>
> SO - take the original idea, and examine how it *might* be improved .....
>
> The problem here is that "put ... before ..." requires all existing data
> in the destination container to be moved (i.e. copied) to make space.
>
> SO, instead, we can use "put ... into char x to y of ..." - since it uses
> char indexing, it takes constant time (i.e. no scan, just directly replace
> the chars.  I've attached my complete code so anyone can try it easily -
> for my test data of approx 8000 lines, this takes 8 msecs, versus 588 for
> the original version.
>
> -- Alex.
>
> on mouseup
>    put fld "fldout" into tstart
>
>    put tstart into ta
>    repeat 200 times
>       put tstart after ta
>    end repeat
>    put ta into tstart
>
>    put the millisecs into t1
>    put revers(ta) into tb
>    put the millisecs - t1 & CR after msg
>
>    put tstart into ta
>    put the millisecs into t1
>    put qrevers(ta) into tc
>    put the millisecs - t1 & CR after msg
>
>    if tb = tc then put "OK" after msg
> end mouseup
>
> function revers p
>    repeat for each line l  in p
>       put L &CR before t
>    end repeat
>    return t
> end revers
>
> function qrevers p
>    put p into t
>    put the number of chars in t into tlen
>    repeat for each line l in p
>       put the number of chars in l into tl
>       put l & cr into char (tLen-tl) to tLen of t
>       subtract (tl+1) from tLen
>    end repeat
>    return t
> end qrevers
>
>
> On 08/02/2015 21:52, J. Landman Gay wrote:
>
>> Just tinkering around on a lazy Sunday, and I thought I'd come up with a
>> neat way to reverse a list without using the traditional clunky method:
>>
>> function reverseSort pList
>>   repeat for each line l in pList
>>     put l & cr before tList
>>   end repeat
>>   return tList
>> end reverseSort
>>
>> One of the best things I learned from a past LC converence came from
>> Jerry Daniels who said "let the engine do it." It's almost always faster
>> and more efficient. With that in mind I wrote this:
>>
>> 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
>>
>> function reverseSort pTxt
>>   subtract 1 from sNum
>>   return sNum && pTxt
>> end reverseSort
>>
>> Works great and I was proud. Then I did some timing tests and found out
>> the two methods are very close to equivalent in timing, and on long lists,
>> the first way is actually faster.
>>
>> So much for improving on LC's text chunking speed. Pah.
>>
>>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Reverse a list

Alex Tweedly
Wow. I can see why LC7 would be expected to be slower for this case - in
the multi-byte Unicode world, char indexing isn't as simple as it used
to be. BUT in this specific case, you can actually replace all use of
"char" by "byte" and still be sure it works (ummm - except if the CR
equivalent can be multi-byte - but I'll choose to ignore that :-)  
However, using position by byte is just as slow !!

I'll have to play around a bit more to see if I can fathom out why that
should be.

- -Alex.

On 08/02/2015 23:18, Mike Bonner wrote:

> Version 6.6.2, your "by position" method is by FAR the fastest 26 millisec
> for 80k lines.  repeat takes almost 9 seconds.  The sort function method
> not passing text back and forth,  takes 102 millisec which isn't slouchy by
> any means.
>
> Jump to version 7.0.1 and the by position method needs some major love.
> The repeat method is almost twice as fast in 7, the sort without passing
> the text method is within a few millisec of 6.6.2, and the by position
> method is unusable at 21 seconds.  REALLY hope they get some optimization
> going soon.
>
> On Sun, Feb 8, 2015 at 3:37 PM, Alex Tweedly <[hidden email]> wrote:
>
>> Indeed. Jerry was (as usual) correct - if the engine can do it, then the
>> engine will normally be faster.
>>
>> BUT sorting a list requires moving the data around quite a lot, AND
>> sorting something that actually reverses it can be a pathologically bad
>> case (e.g. if the engine uses any variant of quicksort())..
>>
>> SO - take the original idea, and examine how it *might* be improved .....
>>
>> The problem here is that "put ... before ..." requires all existing data
>> in the destination container to be moved (i.e. copied) to make space.
>>
>> SO, instead, we can use "put ... into char x to y of ..." - since it uses
>> char indexing, it takes constant time (i.e. no scan, just directly replace
>> the chars.  I've attached my complete code so anyone can try it easily -
>> for my test data of approx 8000 lines, this takes 8 msecs, versus 588 for
>> the original version.
>>
>> -- Alex.
>>
>> on mouseup
>>     put fld "fldout" into tstart
>>
>>     put tstart into ta
>>     repeat 200 times
>>        put tstart after ta
>>     end repeat
>>     put ta into tstart
>>
>>     put the millisecs into t1
>>     put revers(ta) into tb
>>     put the millisecs - t1 & CR after msg
>>
>>     put tstart into ta
>>     put the millisecs into t1
>>     put qrevers(ta) into tc
>>     put the millisecs - t1 & CR after msg
>>
>>     if tb = tc then put "OK" after msg
>> end mouseup
>>
>> function revers p
>>     repeat for each line l  in p
>>        put L &CR before t
>>     end repeat
>>     return t
>> end revers
>>
>> function qrevers p
>>     put p into t
>>     put the number of chars in t into tlen
>>     repeat for each line l in p
>>        put the number of chars in l into tl
>>        put l & cr into char (tLen-tl) to tLen of t
>>        subtract (tl+1) from tLen
>>     end repeat
>>     return t
>> end qrevers
>>
>>
>> On 08/02/2015 21:52, J. Landman Gay wrote:
>>
>>> Just tinkering around on a lazy Sunday, and I thought I'd come up with a
>>> neat way to reverse a list without using the traditional clunky method:
>>>
>>> function reverseSort pList
>>>    repeat for each line l in pList
>>>      put l & cr before tList
>>>    end repeat
>>>    return tList
>>> end reverseSort
>>>
>>> One of the best things I learned from a past LC converence came from
>>> Jerry Daniels who said "let the engine do it." It's almost always faster
>>> and more efficient. With that in mind I wrote this:
>>>
>>> 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
>>>
>>> function reverseSort pTxt
>>>    subtract 1 from sNum
>>>    return sNum && pTxt
>>> end reverseSort
>>>
>>> Works great and I was proud. Then I did some timing tests and found out
>>> the two methods are very close to equivalent in timing, and on long lists,
>>> the first way is actually faster.
>>>
>>> So much for improving on LC's text chunking speed. Pah.
>>>
>>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Reverse a list

Mike Bonner
Yeah, the difference is rather shocking.  Really hoping for a major tuneup.


On Sun, Feb 8, 2015 at 4:37 PM, Alex Tweedly <[hidden email]> wrote:

> Wow. I can see why LC7 would be expected to be slower for this case - in
> the multi-byte Unicode world, char indexing isn't as simple as it used to
> be. BUT in this specific case, you can actually replace all use of "char"
> by "byte" and still be sure it works (ummm - except if the CR equivalent
> can be multi-byte - but I'll choose to ignore that :-)   However, using
> position by byte is just as slow !!
>
> I'll have to play around a bit more to see if I can fathom out why that
> should be.
>
> - -Alex.
>
>
> On 08/02/2015 23:18, Mike Bonner wrote:
>
>> Version 6.6.2, your "by position" method is by FAR the fastest 26 millisec
>> for 80k lines.  repeat takes almost 9 seconds.  The sort function method
>> not passing text back and forth,  takes 102 millisec which isn't slouchy
>> by
>> any means.
>>
>> Jump to version 7.0.1 and the by position method needs some major love.
>> The repeat method is almost twice as fast in 7, the sort without passing
>> the text method is within a few millisec of 6.6.2, and the by position
>> method is unusable at 21 seconds.  REALLY hope they get some optimization
>> going soon.
>>
>> On Sun, Feb 8, 2015 at 3:37 PM, Alex Tweedly <[hidden email]> wrote:
>>
>>  Indeed. Jerry was (as usual) correct - if the engine can do it, then the
>>> engine will normally be faster.
>>>
>>> BUT sorting a list requires moving the data around quite a lot, AND
>>> sorting something that actually reverses it can be a pathologically bad
>>> case (e.g. if the engine uses any variant of quicksort())..
>>>
>>> SO - take the original idea, and examine how it *might* be improved .....
>>>
>>> The problem here is that "put ... before ..." requires all existing data
>>> in the destination container to be moved (i.e. copied) to make space.
>>>
>>> SO, instead, we can use "put ... into char x to y of ..." - since it uses
>>> char indexing, it takes constant time (i.e. no scan, just directly
>>> replace
>>> the chars.  I've attached my complete code so anyone can try it easily -
>>> for my test data of approx 8000 lines, this takes 8 msecs, versus 588 for
>>> the original version.
>>>
>>> -- Alex.
>>>
>>> on mouseup
>>>     put fld "fldout" into tstart
>>>
>>>     put tstart into ta
>>>     repeat 200 times
>>>        put tstart after ta
>>>     end repeat
>>>     put ta into tstart
>>>
>>>     put the millisecs into t1
>>>     put revers(ta) into tb
>>>     put the millisecs - t1 & CR after msg
>>>
>>>     put tstart into ta
>>>     put the millisecs into t1
>>>     put qrevers(ta) into tc
>>>     put the millisecs - t1 & CR after msg
>>>
>>>     if tb = tc then put "OK" after msg
>>> end mouseup
>>>
>>> function revers p
>>>     repeat for each line l  in p
>>>        put L &CR before t
>>>     end repeat
>>>     return t
>>> end revers
>>>
>>> function qrevers p
>>>     put p into t
>>>     put the number of chars in t into tlen
>>>     repeat for each line l in p
>>>        put the number of chars in l into tl
>>>        put l & cr into char (tLen-tl) to tLen of t
>>>        subtract (tl+1) from tLen
>>>     end repeat
>>>     return t
>>> end qrevers
>>>
>>>
>>> On 08/02/2015 21:52, J. Landman Gay wrote:
>>>
>>>  Just tinkering around on a lazy Sunday, and I thought I'd come up with a
>>>> neat way to reverse a list without using the traditional clunky method:
>>>>
>>>> function reverseSort pList
>>>>    repeat for each line l in pList
>>>>      put l & cr before tList
>>>>    end repeat
>>>>    return tList
>>>> end reverseSort
>>>>
>>>> One of the best things I learned from a past LC converence came from
>>>> Jerry Daniels who said "let the engine do it." It's almost always faster
>>>> and more efficient. With that in mind I wrote this:
>>>>
>>>> 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
>>>>
>>>> function reverseSort pTxt
>>>>    subtract 1 from sNum
>>>>    return sNum && pTxt
>>>> end reverseSort
>>>>
>>>> Works great and I was proud. Then I did some timing tests and found out
>>>> the two methods are very close to equivalent in timing, and on long
>>>> lists,
>>>> the first way is actually faster.
>>>>
>>>> So much for improving on LC's text chunking speed. Pah.
>>>>
>>>>
>>>>  _______________________________________________
>>> use-livecode mailing list
>>> [hidden email]
>>> Please visit this url to subscribe, unsubscribe and manage your
>>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>>
>>>  _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Reverse a list

J. Landman Gay
In reply to this post by Mike Bonner
On 2/8/2015 5:18 PM, Mike Bonner wrote:
> The sort function method
> not passing text back and forth

Odd. I started out that way, returning only the numerical reference. The
sort wasn't stable and the list got jumbled. When I added the text
parameter in, it worked. I've just reverted my function to omit the text
again, and now it does work. Either I did something I don't remember, or
there's gremlins.

Anyway, having the two of you go at it has been interesting, I was
hoping this would spark a coding challenge. The business with byte
counting was unexpected.

--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Reverse a list

Kay C Lan
In reply to this post by Alex Tweedly
On Mon, Feb 9, 2015 at 7:37 AM, Alex Tweedly <[hidden email]> wrote:

> Wow. I can see why LC7 would be expected to be slower for this case - in
> the multi-byte Unicode world,
>

It just doesn't appear to be characters and bytes. I tried a slightly
different approach to Jacques, using brute force and lines, and get a
slightly faster response in 6.6.5 than Jacque, but considerably slower in
7.0.2 rc2. - see krevers(ta)

It should also be pointed out that all the results are WRONG! They all
leave a trailing CR which is easy enough to handle, BUT, if your field had
the last line "This is the last line" and the insertion point was at the
end of the line, then I would expect the first line of the reverse sort to
be "This is the last line" and that's what all the functions produce. But
if your last line was "This is the last line" and there was a CR and the
insertion point was sitting on the line below I would expect a reverse sort
to produce a blank line and the 2nd line would read "this is the last line".

I know this is an in built feature of LC and what it defines as a line, and
in most circumstances this is very convenient, but depending on what you're
trying to achieve the current solutions may not give the exact output you
require.

6.6.5

There are 1880 lines in tstart
There are now 9400 lines in tstart
revers(ta) took 350 ms
qrevers(ta) took 5 ms
Output OK
krevers(ta) took 328 ms
Output OK

7.0.2 rc2

There are 1880 lines in tstart
There are now 9396 lines in tstart
revers(ta) took 354 ms
qrevers(ta) took 542845 ms
Output OK
krevers(ta) took 2051 ms
Output OK

I only had a 1880 line piece of text at hand so I used a repeat loop to get
above 8000 lines which seemed the bar people were using to measure. The
reason there is 9400 <> 9396 is because the last test I did with 6.6.5 had
a cr at the end of the line so the insertion point was on the line below,
with 7.0.2 the insertion point was at the end of the line.

I've left a hard breakpoint at the end of the code so you can compare the
tops and bottoms of ta, tb, tc and tk.

Note the extra test to see of the first char of the original matches the
last char of the result and the last char of the original matches the first
char of the result. In my tests none were correct.

(watch for line wraps)

on mouseup
   put fld "fldout" into tstart

   put "There are " & the number of lines of tStart & " lines in tstart" &
cr into msg
   put tstart into ta
   repeat 4 times
      put tstart after ta
   end repeat
   put ta into tstart
   put "There are now " &  the number of lines of tStart & " lines in tstart"
& cr after msg

   put the millisecs into t1
   put revers(ta) into tb
   put "revers(ta) took " &  the millisecs - t1 & " ms" & CR after msg

   put tstart into ta
   put the millisecs into t1
   put qrevers(ta) into tc
   put "qrevers(ta) took " & the millisecs - t1 & " ms " & CR after msg

   if tb = tc then put "Output OK" & cr after msg
   if ((char 1 of ta = char -1 of tb) AND (char -1 of ta = char 1 of tb))
then put "revers(ta) is correct" & cr after msg
   if ((char 1 of ta = char -1 of tc) AND (char -1 of ta = char 1 of tc))
then put "krevers(ta) is correct" & cr after msg

   put the millisec into t1
   put krevers(ta) into tk
   put "krevers(ta) took " & the millisec - t1 & " ms" & cr after msg
   --breakpoint
   if tb = tk then
      put "Output OK"  & cr after msg
   else
      put "Fail!" & cr after msg
   end if
   if ((char 1 of ta = char -1 of tb) AND (char -1 of ta = char 1 of tb))
then put "revers(ta) is correct" & cr after msg
   if ((char 1 of ta = char -1 of tk) AND (char -1 of ta = char 1 of tk))
then put "krevers(ta) is correct" & cr after msg
   breakpoint
end mouseup

function revers p
   repeat for each line l  in p
      put L & CR before t
   end repeat
   return t
end revers

function qrevers p
   put p into t
   put the number of chars in t into tlen
   repeat for each line l in p
      put the number of chars in l into tl
      put l & cr into char (tLen-tl) to tLen of t
      subtract (tl+1) from tLen
   end repeat
   return t
end qrevers

function krevers p
   put "" into t
   repeat for each line l in p
      put l & cr & t into t
   end repeat
   return t
end krevers
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Reverse a list

Dave Cragg-2
In reply to this post by Alex Tweedly
I tried an array method:


function arevers p
   split p by cr
   put empty into t
   put the number of lines in the keys of p into tNumElems
   repeat with i = tNumElems down to 1
      put p[i] & cr after t
   end repeat
   return t
end arevers

This is slower than Alex's method in 6.0.2 (21 ms vs 9ms). And while slower in 7.0.1, now much faster that Alex's method. (74 ms vs 446ms)

The increase in speed of the "put before" method was interesting (from 242ms to 92ms)


Cheers
Dave Cragg


> On 8 Feb 2015, at 23:37, Alex Tweedly <[hidden email]> wrote:
>
> Wow. I can see why LC7 would be expected to be slower for this case - in the multi-byte Unicode world, char indexing isn't as simple as it used to be. BUT in this specific case, you can actually replace all use of "char" by "byte" and still be sure it works (ummm - except if the CR equivalent can be multi-byte - but I'll choose to ignore that :-)   However, using position by byte is just as slow !!
>
> I'll have to play around a bit more to see if I can fathom out why that should be.
>
> - -Alex.
>
> On 08/02/2015 23:18, Mike Bonner wrote:
>> Version 6.6.2, your "by position" method is by FAR the fastest 26 millisec
>> for 80k lines.  repeat takes almost 9 seconds.  The sort function method
>> not passing text back and forth,  takes 102 millisec which isn't slouchy by
>> any means.
>>
>> Jump to version 7.0.1 and the by position method needs some major love.
>> The repeat method is almost twice as fast in 7, the sort without passing
>> the text method is within a few millisec of 6.6.2, and the by position
>> method is unusable at 21 seconds.  REALLY hope they get some optimization
>> going soon.
>>
>> On Sun, Feb 8, 2015 at 3:37 PM, Alex Tweedly <[hidden email]> wrote:
>>
>>> Indeed. Jerry was (as usual) correct - if the engine can do it, then the
>>> engine will normally be faster.
>>>
>>> BUT sorting a list requires moving the data around quite a lot, AND
>>> sorting something that actually reverses it can be a pathologically bad
>>> case (e.g. if the engine uses any variant of quicksort())..
>>>
>>> SO - take the original idea, and examine how it *might* be improved .....
>>>
>>> The problem here is that "put ... before ..." requires all existing data
>>> in the destination container to be moved (i.e. copied) to make space.
>>>
>>> SO, instead, we can use "put ... into char x to y of ..." - since it uses
>>> char indexing, it takes constant time (i.e. no scan, just directly replace
>>> the chars.  I've attached my complete code so anyone can try it easily -
>>> for my test data of approx 8000 lines, this takes 8 msecs, versus 588 for
>>> the original version.
>>>
>>> -- Alex.
>>>
>>> on mouseup
>>>    put fld "fldout" into tstart
>>>
>>>    put tstart into ta
>>>    repeat 200 times
>>>       put tstart after ta
>>>    end repeat
>>>    put ta into tstart
>>>
>>>    put the millisecs into t1
>>>    put revers(ta) into tb
>>>    put the millisecs - t1 & CR after msg
>>>
>>>    put tstart into ta
>>>    put the millisecs into t1
>>>    put qrevers(ta) into tc
>>>    put the millisecs - t1 & CR after msg
>>>
>>>    if tb = tc then put "OK" after msg
>>> end mouseup
>>>
>>> function revers p
>>>    repeat for each line l  in p
>>>       put L &CR before t
>>>    end repeat
>>>    return t
>>> end revers
>>>
>>> function qrevers p
>>>    put p into t
>>>    put the number of chars in t into tlen
>>>    repeat for each line l in p
>>>       put the number of chars in l into tl
>>>       put l & cr into char (tLen-tl) to tLen of t
>>>       subtract (tl+1) from tLen
>>>    end repeat
>>>    return t
>>> end qrevers
>>>
>>>
>>> On 08/02/2015 21:52, J. Landman Gay wrote:
>>>
>>>> Just tinkering around on a lazy Sunday, and I thought I'd come up with a
>>>> neat way to reverse a list without using the traditional clunky method:
>>>>
>>>> function reverseSort pList
>>>>   repeat for each line l in pList
>>>>     put l & cr before tList
>>>>   end repeat
>>>>   return tList
>>>> end reverseSort
>>>>
>>>> One of the best things I learned from a past LC converence came from
>>>> Jerry Daniels who said "let the engine do it." It's almost always faster
>>>> and more efficient. With that in mind I wrote this:
>>>>
>>>> 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
>>>>
>>>> function reverseSort pTxt
>>>>   subtract 1 from sNum
>>>>   return sNum && pTxt
>>>> end reverseSort
>>>>
>>>> Works great and I was proud. Then I did some timing tests and found out
>>>> the two methods are very close to equivalent in timing, and on long lists,
>>>> the first way is actually faster.
>>>>
>>>> So much for improving on LC's text chunking speed. Pah.
>>>>
>>>>
>>> _______________________________________________
>>> use-livecode mailing list
>>> [hidden email]
>>> Please visit this url to subscribe, unsubscribe and manage your
>>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Reverse a list

Mike Kerner
What about using an index, instead of the actual data?  With the times
quoted in 7, I wonder if using an SQLite or mySQL db would be faster.

On Mon, Feb 9, 2015 at 7:03 AM, Dave Cragg <[hidden email]>
wrote:

> I tried an array method:
>
>
> function arevers p
>    split p by cr
>    put empty into t
>    put the number of lines in the keys of p into tNumElems
>    repeat with i = tNumElems down to 1
>       put p[i] & cr after t
>    end repeat
>    return t
> end arevers
>
> This is slower than Alex's method in 6.0.2 (21 ms vs 9ms). And while
> slower in 7.0.1, now much faster that Alex's method. (74 ms vs 446ms)
>
> The increase in speed of the "put before" method was interesting (from
> 242ms to 92ms)
>
>
> Cheers
> Dave Cragg
>
>
> > On 8 Feb 2015, at 23:37, Alex Tweedly <[hidden email]> wrote:
> >
> > Wow. I can see why LC7 would be expected to be slower for this case - in
> the multi-byte Unicode world, char indexing isn't as simple as it used to
> be. BUT in this specific case, you can actually replace all use of "char"
> by "byte" and still be sure it works (ummm - except if the CR equivalent
> can be multi-byte - but I'll choose to ignore that :-)   However, using
> position by byte is just as slow !!
> >
> > I'll have to play around a bit more to see if I can fathom out why that
> should be.
> >
> > - -Alex.
> >
> > On 08/02/2015 23:18, Mike Bonner wrote:
> >> Version 6.6.2, your "by position" method is by FAR the fastest 26
> millisec
> >> for 80k lines.  repeat takes almost 9 seconds.  The sort function method
> >> not passing text back and forth,  takes 102 millisec which isn't
> slouchy by
> >> any means.
> >>
> >> Jump to version 7.0.1 and the by position method needs some major love.
> >> The repeat method is almost twice as fast in 7, the sort without passing
> >> the text method is within a few millisec of 6.6.2, and the by position
> >> method is unusable at 21 seconds.  REALLY hope they get some
> optimization
> >> going soon.
> >>
> >> On Sun, Feb 8, 2015 at 3:37 PM, Alex Tweedly <[hidden email]> wrote:
> >>
> >>> Indeed. Jerry was (as usual) correct - if the engine can do it, then
> the
> >>> engine will normally be faster.
> >>>
> >>> BUT sorting a list requires moving the data around quite a lot, AND
> >>> sorting something that actually reverses it can be a pathologically bad
> >>> case (e.g. if the engine uses any variant of quicksort())..
> >>>
> >>> SO - take the original idea, and examine how it *might* be improved
> .....
> >>>
> >>> The problem here is that "put ... before ..." requires all existing
> data
> >>> in the destination container to be moved (i.e. copied) to make space.
> >>>
> >>> SO, instead, we can use "put ... into char x to y of ..." - since it
> uses
> >>> char indexing, it takes constant time (i.e. no scan, just directly
> replace
> >>> the chars.  I've attached my complete code so anyone can try it easily
> -
> >>> for my test data of approx 8000 lines, this takes 8 msecs, versus 588
> for
> >>> the original version.
> >>>
> >>> -- Alex.
> >>>
> >>> on mouseup
> >>>    put fld "fldout" into tstart
> >>>
> >>>    put tstart into ta
> >>>    repeat 200 times
> >>>       put tstart after ta
> >>>    end repeat
> >>>    put ta into tstart
> >>>
> >>>    put the millisecs into t1
> >>>    put revers(ta) into tb
> >>>    put the millisecs - t1 & CR after msg
> >>>
> >>>    put tstart into ta
> >>>    put the millisecs into t1
> >>>    put qrevers(ta) into tc
> >>>    put the millisecs - t1 & CR after msg
> >>>
> >>>    if tb = tc then put "OK" after msg
> >>> end mouseup
> >>>
> >>> function revers p
> >>>    repeat for each line l  in p
> >>>       put L &CR before t
> >>>    end repeat
> >>>    return t
> >>> end revers
> >>>
> >>> function qrevers p
> >>>    put p into t
> >>>    put the number of chars in t into tlen
> >>>    repeat for each line l in p
> >>>       put the number of chars in l into tl
> >>>       put l & cr into char (tLen-tl) to tLen of t
> >>>       subtract (tl+1) from tLen
> >>>    end repeat
> >>>    return t
> >>> end qrevers
> >>>
> >>>
> >>> On 08/02/2015 21:52, J. Landman Gay wrote:
> >>>
> >>>> Just tinkering around on a lazy Sunday, and I thought I'd come up
> with a
> >>>> neat way to reverse a list without using the traditional clunky
> method:
> >>>>
> >>>> function reverseSort pList
> >>>>   repeat for each line l in pList
> >>>>     put l & cr before tList
> >>>>   end repeat
> >>>>   return tList
> >>>> end reverseSort
> >>>>
> >>>> One of the best things I learned from a past LC converence came from
> >>>> Jerry Daniels who said "let the engine do it." It's almost always
> faster
> >>>> and more efficient. With that in mind I wrote this:
> >>>>
> >>>> 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
> >>>>
> >>>> function reverseSort pTxt
> >>>>   subtract 1 from sNum
> >>>>   return sNum && pTxt
> >>>> end reverseSort
> >>>>
> >>>> Works great and I was proud. Then I did some timing tests and found
> out
> >>>> the two methods are very close to equivalent in timing, and on long
> lists,
> >>>> the first way is actually faster.
> >>>>
> >>>> So much for improving on LC's text chunking speed. Pah.
> >>>>
> >>>>
> >>> _______________________________________________
> >>> use-livecode mailing list
> >>> [hidden email]
> >>> Please visit this url to subscribe, unsubscribe and manage your
> >>> subscription preferences:
> >>> http://lists.runrev.com/mailman/listinfo/use-livecode
> >>>
> >> _______________________________________________
> >> use-livecode mailing list
> >> [hidden email]
> >> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> >> http://lists.runrev.com/mailman/listinfo/use-livecode
> >
> >
> > _______________________________________________
> > use-livecode mailing list
> > [hidden email]
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> 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
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Reverse a list

Mike Bonner
I like the idea Mike K.
The slow part with the array method is rebuilding the list.  Why not just
build the array, grab and reverse numeric sort the keys and use the data
directly from the array? For 80k lines, the split takes 24 ms.  Putting the
keys into a variable, and reverse sorting them takes 2 ms (6.6.2)   On
7.0.1 the split takes 56ms, placing the keys and sorting them takes 11ms
total 67ms  fastest, the nearest being sort with function at 125ms.  After
that is repeat at over 2 sec and the broken by position at 22+ seconds.

Unless the whole list will be spit back out for display purposes, how its
stored shouldn't matter right?

Anyone up to test sqlite?  In memory db should be pretty zippy I'd guess.



On Mon, Feb 9, 2015 at 7:12 AM, Mike Kerner <[hidden email]>
wrote:

> What about using an index, instead of the actual data?  With the times
> quoted in 7, I wonder if using an SQLite or mySQL db would be faster.
>
> On Mon, Feb 9, 2015 at 7:03 AM, Dave Cragg <[hidden email]>
> wrote:
>
> > I tried an array method:
> >
> >
> > function arevers p
> >    split p by cr
> >    put empty into t
> >    put the number of lines in the keys of p into tNumElems
> >    repeat with i = tNumElems down to 1
> >       put p[i] & cr after t
> >    end repeat
> >    return t
> > end arevers
> >
> > This is slower than Alex's method in 6.0.2 (21 ms vs 9ms). And while
> > slower in 7.0.1, now much faster that Alex's method. (74 ms vs 446ms)
> >
> > The increase in speed of the "put before" method was interesting (from
> > 242ms to 92ms)
> >
> >
> > Cheers
> > Dave Cragg
> >
> >
> > > On 8 Feb 2015, at 23:37, Alex Tweedly <[hidden email]> wrote:
> > >
> > > Wow. I can see why LC7 would be expected to be slower for this case -
> in
> > the multi-byte Unicode world, char indexing isn't as simple as it used to
> > be. BUT in this specific case, you can actually replace all use of "char"
> > by "byte" and still be sure it works (ummm - except if the CR equivalent
> > can be multi-byte - but I'll choose to ignore that :-)   However, using
> > position by byte is just as slow !!
> > >
> > > I'll have to play around a bit more to see if I can fathom out why that
> > should be.
> > >
> > > - -Alex.
> > >
> > > On 08/02/2015 23:18, Mike Bonner wrote:
> > >> Version 6.6.2, your "by position" method is by FAR the fastest 26
> > millisec
> > >> for 80k lines.  repeat takes almost 9 seconds.  The sort function
> method
> > >> not passing text back and forth,  takes 102 millisec which isn't
> > slouchy by
> > >> any means.
> > >>
> > >> Jump to version 7.0.1 and the by position method needs some major
> love.
> > >> The repeat method is almost twice as fast in 7, the sort without
> passing
> > >> the text method is within a few millisec of 6.6.2, and the by position
> > >> method is unusable at 21 seconds.  REALLY hope they get some
> > optimization
> > >> going soon.
> > >>
> > >> On Sun, Feb 8, 2015 at 3:37 PM, Alex Tweedly <[hidden email]>
> wrote:
> > >>
> > >>> Indeed. Jerry was (as usual) correct - if the engine can do it, then
> > the
> > >>> engine will normally be faster.
> > >>>
> > >>> BUT sorting a list requires moving the data around quite a lot, AND
> > >>> sorting something that actually reverses it can be a pathologically
> bad
> > >>> case (e.g. if the engine uses any variant of quicksort())..
> > >>>
> > >>> SO - take the original idea, and examine how it *might* be improved
> > .....
> > >>>
> > >>> The problem here is that "put ... before ..." requires all existing
> > data
> > >>> in the destination container to be moved (i.e. copied) to make space.
> > >>>
> > >>> SO, instead, we can use "put ... into char x to y of ..." - since it
> > uses
> > >>> char indexing, it takes constant time (i.e. no scan, just directly
> > replace
> > >>> the chars.  I've attached my complete code so anyone can try it
> easily
> > -
> > >>> for my test data of approx 8000 lines, this takes 8 msecs, versus 588
> > for
> > >>> the original version.
> > >>>
> > >>> -- Alex.
> > >>>
> > >>> on mouseup
> > >>>    put fld "fldout" into tstart
> > >>>
> > >>>    put tstart into ta
> > >>>    repeat 200 times
> > >>>       put tstart after ta
> > >>>    end repeat
> > >>>    put ta into tstart
> > >>>
> > >>>    put the millisecs into t1
> > >>>    put revers(ta) into tb
> > >>>    put the millisecs - t1 & CR after msg
> > >>>
> > >>>    put tstart into ta
> > >>>    put the millisecs into t1
> > >>>    put qrevers(ta) into tc
> > >>>    put the millisecs - t1 & CR after msg
> > >>>
> > >>>    if tb = tc then put "OK" after msg
> > >>> end mouseup
> > >>>
> > >>> function revers p
> > >>>    repeat for each line l  in p
> > >>>       put L &CR before t
> > >>>    end repeat
> > >>>    return t
> > >>> end revers
> > >>>
> > >>> function qrevers p
> > >>>    put p into t
> > >>>    put the number of chars in t into tlen
> > >>>    repeat for each line l in p
> > >>>       put the number of chars in l into tl
> > >>>       put l & cr into char (tLen-tl) to tLen of t
> > >>>       subtract (tl+1) from tLen
> > >>>    end repeat
> > >>>    return t
> > >>> end qrevers
> > >>>
> > >>>
> > >>> On 08/02/2015 21:52, J. Landman Gay wrote:
> > >>>
> > >>>> Just tinkering around on a lazy Sunday, and I thought I'd come up
> > with a
> > >>>> neat way to reverse a list without using the traditional clunky
> > method:
> > >>>>
> > >>>> function reverseSort pList
> > >>>>   repeat for each line l in pList
> > >>>>     put l & cr before tList
> > >>>>   end repeat
> > >>>>   return tList
> > >>>> end reverseSort
> > >>>>
> > >>>> One of the best things I learned from a past LC converence came from
> > >>>> Jerry Daniels who said "let the engine do it." It's almost always
> > faster
> > >>>> and more efficient. With that in mind I wrote this:
> > >>>>
> > >>>> 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
> > >>>>
> > >>>> function reverseSort pTxt
> > >>>>   subtract 1 from sNum
> > >>>>   return sNum && pTxt
> > >>>> end reverseSort
> > >>>>
> > >>>> Works great and I was proud. Then I did some timing tests and found
> > out
> > >>>> the two methods are very close to equivalent in timing, and on long
> > lists,
> > >>>> the first way is actually faster.
> > >>>>
> > >>>> So much for improving on LC's text chunking speed. Pah.
> > >>>>
> > >>>>
> > >>> _______________________________________________
> > >>> use-livecode mailing list
> > >>> [hidden email]
> > >>> Please visit this url to subscribe, unsubscribe and manage your
> > >>> subscription preferences:
> > >>> http://lists.runrev.com/mailman/listinfo/use-livecode
> > >>>
> > >> _______________________________________________
> > >> use-livecode mailing list
> > >> [hidden email]
> > >> Please visit this url to subscribe, unsubscribe and manage your
> > subscription preferences:
> > >> http://lists.runrev.com/mailman/listinfo/use-livecode
> > >
> > >
> > > _______________________________________________
> > > use-livecode mailing list
> > > [hidden email]
> > > Please visit this url to subscribe, unsubscribe and manage your
> > subscription preferences:
> > > http://lists.runrev.com/mailman/listinfo/use-livecode
> >
> >
> > _______________________________________________
> > use-livecode mailing list
> > [hidden email]
> > 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
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Reverse a list

Mike Kerner
If you use SQLite or mySQL, you'd have to do the same thing with the index,
so unless you already have the data structure in place, you'ld have to
create the table, populate the table with the values and the indexes, and
then order by the index and read the data back, but all of that is done
with the db commands in the language.

On Mon, Feb 9, 2015 at 10:08 AM, Mike Bonner <[hidden email]> wrote:

> I like the idea Mike K.
> The slow part with the array method is rebuilding the list.  Why not just
> build the array, grab and reverse numeric sort the keys and use the data
> directly from the array? For 80k lines, the split takes 24 ms.  Putting the
> keys into a variable, and reverse sorting them takes 2 ms (6.6.2)   On
> 7.0.1 the split takes 56ms, placing the keys and sorting them takes 11ms
> total 67ms  fastest, the nearest being sort with function at 125ms.  After
> that is repeat at over 2 sec and the broken by position at 22+ seconds.
>
> Unless the whole list will be spit back out for display purposes, how its
> stored shouldn't matter right?
>
> Anyone up to test sqlite?  In memory db should be pretty zippy I'd guess.
>
>
>
> On Mon, Feb 9, 2015 at 7:12 AM, Mike Kerner <[hidden email]>
> wrote:
>
> > What about using an index, instead of the actual data?  With the times
> > quoted in 7, I wonder if using an SQLite or mySQL db would be faster.
> >
> > On Mon, Feb 9, 2015 at 7:03 AM, Dave Cragg <[hidden email]>
> > wrote:
> >
> > > I tried an array method:
> > >
> > >
> > > function arevers p
> > >    split p by cr
> > >    put empty into t
> > >    put the number of lines in the keys of p into tNumElems
> > >    repeat with i = tNumElems down to 1
> > >       put p[i] & cr after t
> > >    end repeat
> > >    return t
> > > end arevers
> > >
> > > This is slower than Alex's method in 6.0.2 (21 ms vs 9ms). And while
> > > slower in 7.0.1, now much faster that Alex's method. (74 ms vs 446ms)
> > >
> > > The increase in speed of the "put before" method was interesting (from
> > > 242ms to 92ms)
> > >
> > >
> > > Cheers
> > > Dave Cragg
> > >
> > >
> > > > On 8 Feb 2015, at 23:37, Alex Tweedly <[hidden email]> wrote:
> > > >
> > > > Wow. I can see why LC7 would be expected to be slower for this case -
> > in
> > > the multi-byte Unicode world, char indexing isn't as simple as it used
> to
> > > be. BUT in this specific case, you can actually replace all use of
> "char"
> > > by "byte" and still be sure it works (ummm - except if the CR
> equivalent
> > > can be multi-byte - but I'll choose to ignore that :-)   However, using
> > > position by byte is just as slow !!
> > > >
> > > > I'll have to play around a bit more to see if I can fathom out why
> that
> > > should be.
> > > >
> > > > - -Alex.
> > > >
> > > > On 08/02/2015 23:18, Mike Bonner wrote:
> > > >> Version 6.6.2, your "by position" method is by FAR the fastest 26
> > > millisec
> > > >> for 80k lines.  repeat takes almost 9 seconds.  The sort function
> > method
> > > >> not passing text back and forth,  takes 102 millisec which isn't
> > > slouchy by
> > > >> any means.
> > > >>
> > > >> Jump to version 7.0.1 and the by position method needs some major
> > love.
> > > >> The repeat method is almost twice as fast in 7, the sort without
> > passing
> > > >> the text method is within a few millisec of 6.6.2, and the by
> position
> > > >> method is unusable at 21 seconds.  REALLY hope they get some
> > > optimization
> > > >> going soon.
> > > >>
> > > >> On Sun, Feb 8, 2015 at 3:37 PM, Alex Tweedly <[hidden email]>
> > wrote:
> > > >>
> > > >>> Indeed. Jerry was (as usual) correct - if the engine can do it,
> then
> > > the
> > > >>> engine will normally be faster.
> > > >>>
> > > >>> BUT sorting a list requires moving the data around quite a lot, AND
> > > >>> sorting something that actually reverses it can be a pathologically
> > bad
> > > >>> case (e.g. if the engine uses any variant of quicksort())..
> > > >>>
> > > >>> SO - take the original idea, and examine how it *might* be improved
> > > .....
> > > >>>
> > > >>> The problem here is that "put ... before ..." requires all existing
> > > data
> > > >>> in the destination container to be moved (i.e. copied) to make
> space.
> > > >>>
> > > >>> SO, instead, we can use "put ... into char x to y of ..." - since
> it
> > > uses
> > > >>> char indexing, it takes constant time (i.e. no scan, just directly
> > > replace
> > > >>> the chars.  I've attached my complete code so anyone can try it
> > easily
> > > -
> > > >>> for my test data of approx 8000 lines, this takes 8 msecs, versus
> 588
> > > for
> > > >>> the original version.
> > > >>>
> > > >>> -- Alex.
> > > >>>
> > > >>> on mouseup
> > > >>>    put fld "fldout" into tstart
> > > >>>
> > > >>>    put tstart into ta
> > > >>>    repeat 200 times
> > > >>>       put tstart after ta
> > > >>>    end repeat
> > > >>>    put ta into tstart
> > > >>>
> > > >>>    put the millisecs into t1
> > > >>>    put revers(ta) into tb
> > > >>>    put the millisecs - t1 & CR after msg
> > > >>>
> > > >>>    put tstart into ta
> > > >>>    put the millisecs into t1
> > > >>>    put qrevers(ta) into tc
> > > >>>    put the millisecs - t1 & CR after msg
> > > >>>
> > > >>>    if tb = tc then put "OK" after msg
> > > >>> end mouseup
> > > >>>
> > > >>> function revers p
> > > >>>    repeat for each line l  in p
> > > >>>       put L &CR before t
> > > >>>    end repeat
> > > >>>    return t
> > > >>> end revers
> > > >>>
> > > >>> function qrevers p
> > > >>>    put p into t
> > > >>>    put the number of chars in t into tlen
> > > >>>    repeat for each line l in p
> > > >>>       put the number of chars in l into tl
> > > >>>       put l & cr into char (tLen-tl) to tLen of t
> > > >>>       subtract (tl+1) from tLen
> > > >>>    end repeat
> > > >>>    return t
> > > >>> end qrevers
> > > >>>
> > > >>>
> > > >>> On 08/02/2015 21:52, J. Landman Gay wrote:
> > > >>>
> > > >>>> Just tinkering around on a lazy Sunday, and I thought I'd come up
> > > with a
> > > >>>> neat way to reverse a list without using the traditional clunky
> > > method:
> > > >>>>
> > > >>>> function reverseSort pList
> > > >>>>   repeat for each line l in pList
> > > >>>>     put l & cr before tList
> > > >>>>   end repeat
> > > >>>>   return tList
> > > >>>> end reverseSort
> > > >>>>
> > > >>>> One of the best things I learned from a past LC converence came
> from
> > > >>>> Jerry Daniels who said "let the engine do it." It's almost always
> > > faster
> > > >>>> and more efficient. With that in mind I wrote this:
> > > >>>>
> > > >>>> 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
> > > >>>>
> > > >>>> function reverseSort pTxt
> > > >>>>   subtract 1 from sNum
> > > >>>>   return sNum && pTxt
> > > >>>> end reverseSort
> > > >>>>
> > > >>>> Works great and I was proud. Then I did some timing tests and
> found
> > > out
> > > >>>> the two methods are very close to equivalent in timing, and on
> long
> > > lists,
> > > >>>> the first way is actually faster.
> > > >>>>
> > > >>>> So much for improving on LC's text chunking speed. Pah.
> > > >>>>
> > > >>>>
> > > >>> _______________________________________________
> > > >>> use-livecode mailing list
> > > >>> [hidden email]
> > > >>> Please visit this url to subscribe, unsubscribe and manage your
> > > >>> subscription preferences:
> > > >>> http://lists.runrev.com/mailman/listinfo/use-livecode
> > > >>>
> > > >> _______________________________________________
> > > >> use-livecode mailing list
> > > >> [hidden email]
> > > >> Please visit this url to subscribe, unsubscribe and manage your
> > > subscription preferences:
> > > >> http://lists.runrev.com/mailman/listinfo/use-livecode
> > > >
> > > >
> > > > _______________________________________________
> > > > use-livecode mailing list
> > > > [hidden email]
> > > > Please visit this url to subscribe, unsubscribe and manage your
> > > subscription preferences:
> > > > http://lists.runrev.com/mailman/listinfo/use-livecode
> > >
> > >
> > > _______________________________________________
> > > use-livecode mailing list
> > > [hidden email]
> > > 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
> > [hidden email]
> > Please visit this url to subscribe, unsubscribe and manage your
> > subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
> >
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> 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
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Reverse a list

Mike Kerner
and don't get me wrong, it's not ideal to have to kluge this way, just like
it's not ideal to have to kluge around the last item in a container being
empty.  I'm not a fan of either behavior.  Both should be dealt with, and
this is just another reason why I will be avoiding 7.0 as long as
possible.  I'm just curious for the sake of asking the question, whether
having the db do the sort is faster.

I guess that makes me ask another question:  I wonder if somehow making
unicode optional for those of us who don't deal with two-byte languages
would be possible, so we're not stuck with the extra...stuff...that comes
with it.

On Mon, Feb 9, 2015 at 10:40 AM, Mike Kerner <[hidden email]>
wrote:

> If you use SQLite or mySQL, you'd have to do the same thing with the
> index, so unless you already have the data structure in place, you'ld have
> to create the table, populate the table with the values and the indexes,
> and then order by the index and read the data back, but all of that is done
> with the db commands in the language.
>
> On Mon, Feb 9, 2015 at 10:08 AM, Mike Bonner <[hidden email]> wrote:
>
>> I like the idea Mike K.
>> The slow part with the array method is rebuilding the list.  Why not just
>> build the array, grab and reverse numeric sort the keys and use the data
>> directly from the array? For 80k lines, the split takes 24 ms.  Putting
>> the
>> keys into a variable, and reverse sorting them takes 2 ms (6.6.2)   On
>> 7.0.1 the split takes 56ms, placing the keys and sorting them takes 11ms
>> total 67ms  fastest, the nearest being sort with function at 125ms.  After
>> that is repeat at over 2 sec and the broken by position at 22+ seconds.
>>
>> Unless the whole list will be spit back out for display purposes, how its
>> stored shouldn't matter right?
>>
>> Anyone up to test sqlite?  In memory db should be pretty zippy I'd guess.
>>
>>
>>
>> On Mon, Feb 9, 2015 at 7:12 AM, Mike Kerner <[hidden email]>
>> wrote:
>>
>> > What about using an index, instead of the actual data?  With the times
>> > quoted in 7, I wonder if using an SQLite or mySQL db would be faster.
>> >
>> > On Mon, Feb 9, 2015 at 7:03 AM, Dave Cragg <[hidden email]
>> >
>> > wrote:
>> >
>> > > I tried an array method:
>> > >
>> > >
>> > > function arevers p
>> > >    split p by cr
>> > >    put empty into t
>> > >    put the number of lines in the keys of p into tNumElems
>> > >    repeat with i = tNumElems down to 1
>> > >       put p[i] & cr after t
>> > >    end repeat
>> > >    return t
>> > > end arevers
>> > >
>> > > This is slower than Alex's method in 6.0.2 (21 ms vs 9ms). And while
>> > > slower in 7.0.1, now much faster that Alex's method. (74 ms vs 446ms)
>> > >
>> > > The increase in speed of the "put before" method was interesting (from
>> > > 242ms to 92ms)
>> > >
>> > >
>> > > Cheers
>> > > Dave Cragg
>> > >
>> > >
>> > > > On 8 Feb 2015, at 23:37, Alex Tweedly <[hidden email]> wrote:
>> > > >
>> > > > Wow. I can see why LC7 would be expected to be slower for this case
>> -
>> > in
>> > > the multi-byte Unicode world, char indexing isn't as simple as it
>> used to
>> > > be. BUT in this specific case, you can actually replace all use of
>> "char"
>> > > by "byte" and still be sure it works (ummm - except if the CR
>> equivalent
>> > > can be multi-byte - but I'll choose to ignore that :-)   However,
>> using
>> > > position by byte is just as slow !!
>> > > >
>> > > > I'll have to play around a bit more to see if I can fathom out why
>> that
>> > > should be.
>> > > >
>> > > > - -Alex.
>> > > >
>> > > > On 08/02/2015 23:18, Mike Bonner wrote:
>> > > >> Version 6.6.2, your "by position" method is by FAR the fastest 26
>> > > millisec
>> > > >> for 80k lines.  repeat takes almost 9 seconds.  The sort function
>> > method
>> > > >> not passing text back and forth,  takes 102 millisec which isn't
>> > > slouchy by
>> > > >> any means.
>> > > >>
>> > > >> Jump to version 7.0.1 and the by position method needs some major
>> > love.
>> > > >> The repeat method is almost twice as fast in 7, the sort without
>> > passing
>> > > >> the text method is within a few millisec of 6.6.2, and the by
>> position
>> > > >> method is unusable at 21 seconds.  REALLY hope they get some
>> > > optimization
>> > > >> going soon.
>> > > >>
>> > > >> On Sun, Feb 8, 2015 at 3:37 PM, Alex Tweedly <[hidden email]>
>> > wrote:
>> > > >>
>> > > >>> Indeed. Jerry was (as usual) correct - if the engine can do it,
>> then
>> > > the
>> > > >>> engine will normally be faster.
>> > > >>>
>> > > >>> BUT sorting a list requires moving the data around quite a lot,
>> AND
>> > > >>> sorting something that actually reverses it can be a
>> pathologically
>> > bad
>> > > >>> case (e.g. if the engine uses any variant of quicksort())..
>> > > >>>
>> > > >>> SO - take the original idea, and examine how it *might* be
>> improved
>> > > .....
>> > > >>>
>> > > >>> The problem here is that "put ... before ..." requires all
>> existing
>> > > data
>> > > >>> in the destination container to be moved (i.e. copied) to make
>> space.
>> > > >>>
>> > > >>> SO, instead, we can use "put ... into char x to y of ..." - since
>> it
>> > > uses
>> > > >>> char indexing, it takes constant time (i.e. no scan, just directly
>> > > replace
>> > > >>> the chars.  I've attached my complete code so anyone can try it
>> > easily
>> > > -
>> > > >>> for my test data of approx 8000 lines, this takes 8 msecs, versus
>> 588
>> > > for
>> > > >>> the original version.
>> > > >>>
>> > > >>> -- Alex.
>> > > >>>
>> > > >>> on mouseup
>> > > >>>    put fld "fldout" into tstart
>> > > >>>
>> > > >>>    put tstart into ta
>> > > >>>    repeat 200 times
>> > > >>>       put tstart after ta
>> > > >>>    end repeat
>> > > >>>    put ta into tstart
>> > > >>>
>> > > >>>    put the millisecs into t1
>> > > >>>    put revers(ta) into tb
>> > > >>>    put the millisecs - t1 & CR after msg
>> > > >>>
>> > > >>>    put tstart into ta
>> > > >>>    put the millisecs into t1
>> > > >>>    put qrevers(ta) into tc
>> > > >>>    put the millisecs - t1 & CR after msg
>> > > >>>
>> > > >>>    if tb = tc then put "OK" after msg
>> > > >>> end mouseup
>> > > >>>
>> > > >>> function revers p
>> > > >>>    repeat for each line l  in p
>> > > >>>       put L &CR before t
>> > > >>>    end repeat
>> > > >>>    return t
>> > > >>> end revers
>> > > >>>
>> > > >>> function qrevers p
>> > > >>>    put p into t
>> > > >>>    put the number of chars in t into tlen
>> > > >>>    repeat for each line l in p
>> > > >>>       put the number of chars in l into tl
>> > > >>>       put l & cr into char (tLen-tl) to tLen of t
>> > > >>>       subtract (tl+1) from tLen
>> > > >>>    end repeat
>> > > >>>    return t
>> > > >>> end qrevers
>> > > >>>
>> > > >>>
>> > > >>> On 08/02/2015 21:52, J. Landman Gay wrote:
>> > > >>>
>> > > >>>> Just tinkering around on a lazy Sunday, and I thought I'd come up
>> > > with a
>> > > >>>> neat way to reverse a list without using the traditional clunky
>> > > method:
>> > > >>>>
>> > > >>>> function reverseSort pList
>> > > >>>>   repeat for each line l in pList
>> > > >>>>     put l & cr before tList
>> > > >>>>   end repeat
>> > > >>>>   return tList
>> > > >>>> end reverseSort
>> > > >>>>
>> > > >>>> One of the best things I learned from a past LC converence came
>> from
>> > > >>>> Jerry Daniels who said "let the engine do it." It's almost always
>> > > faster
>> > > >>>> and more efficient. With that in mind I wrote this:
>> > > >>>>
>> > > >>>> 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
>> > > >>>>
>> > > >>>> function reverseSort pTxt
>> > > >>>>   subtract 1 from sNum
>> > > >>>>   return sNum && pTxt
>> > > >>>> end reverseSort
>> > > >>>>
>> > > >>>> Works great and I was proud. Then I did some timing tests and
>> found
>> > > out
>> > > >>>> the two methods are very close to equivalent in timing, and on
>> long
>> > > lists,
>> > > >>>> the first way is actually faster.
>> > > >>>>
>> > > >>>> So much for improving on LC's text chunking speed. Pah.
>> > > >>>>
>> > > >>>>
>> > > >>> _______________________________________________
>> > > >>> use-livecode mailing list
>> > > >>> [hidden email]
>> > > >>> Please visit this url to subscribe, unsubscribe and manage your
>> > > >>> subscription preferences:
>> > > >>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> > > >>>
>> > > >> _______________________________________________
>> > > >> use-livecode mailing list
>> > > >> [hidden email]
>> > > >> Please visit this url to subscribe, unsubscribe and manage your
>> > > subscription preferences:
>> > > >> http://lists.runrev.com/mailman/listinfo/use-livecode
>> > > >
>> > > >
>> > > > _______________________________________________
>> > > > use-livecode mailing list
>> > > > [hidden email]
>> > > > Please visit this url to subscribe, unsubscribe and manage your
>> > > subscription preferences:
>> > > > http://lists.runrev.com/mailman/listinfo/use-livecode
>> > >
>> > >
>> > > _______________________________________________
>> > > use-livecode mailing list
>> > > [hidden email]
>> > > 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
>> > [hidden email]
>> > Please visit this url to subscribe, unsubscribe and manage your
>> > subscription preferences:
>> > http://lists.runrev.com/mailman/listinfo/use-livecode
>> >
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> 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."
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Reverse a list

Bob Sneidar-2
In reply to this post by J. Landman Gay
Yes, but the second way is so much more sophisticated.

Bob S


On Feb 8, 2015, at 13:52 , J. Landman Gay <[hidden email]<mailto:[hidden email]>> wrote:

Just tinkering around on a lazy Sunday, and I thought I'd come up with a neat way to reverse a list without using the traditional clunky method:

function reverseSort pList
 repeat for each line l in pList
   put l & cr before tList
 end repeat
 return tList
end reverseSort

One of the best things I learned from a past LC converence came from Jerry Daniels who said "let the engine do it." It's almost always faster and more efficient. With that in mind I wrote this:

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

function reverseSort pTxt
 subtract 1 from sNum
 return sNum && pTxt
end reverseSort

Works great and I was proud. Then I did some timing tests and found out the two methods are very close to equivalent in timing, and on long lists, the first way is actually faster.

So much for improving on LC's text chunking speed. Pah.

--
Jacqueline Landman Gay         |     [hidden email]<mailto:[hidden email]>

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Reverse a list

Bob Sneidar-2
In reply to this post by Alex Tweedly
Then there is the method of storing the data in a memory based sqLite instance and using SELECT with the ORDER BY DESC ordering term. Might not be faster, but it should be a lot more flexible.

Bob S


On Feb 8, 2015, at 14:37 , Alex Tweedly <[hidden email]<mailto:[hidden email]>> wrote:

Indeed. Jerry was (as usual) correct - if the engine can do it, then the engine will normally be faster.

BUT sorting a list requires moving the data around quite a lot, AND sorting something that actually reverses it can be a pathologically bad case (e.g. if the engine uses any variant of quicksort())..


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Reverse a list

Ali Lloyd
Hi all.

Thanks very much for this thread, it has uncovered a quite inefficient code
path in chunk resolution that we will be able to sort out.

Indeed, I believe that http://quality.runrev.com/show_bug.cgi?id=14504 was
already potentially causing a problem for the 'char' chunk. In theory the
engine should detect the use of a native string and process it as such,
thereby circumventing any of the the unicode specific code paths. In 7.0 it
is worth testing with the codeunit chunk instead if you know you have a
native string - if the codeunit version is faster then something related to
bug 14504 is probably causing the problem.

Ali

On 9 February 2015 at 16:06, Bob Sneidar <[hidden email]>
wrote:

> Then there is the method of storing the data in a memory based sqLite
> instance and using SELECT with the ORDER BY DESC ordering term. Might not
> be faster, but it should be a lot more flexible.
>
> Bob S
>
>
> On Feb 8, 2015, at 14:37 , Alex Tweedly <[hidden email]<mailto:
> [hidden email]>> wrote:
>
> Indeed. Jerry was (as usual) correct - if the engine can do it, then the
> engine will normally be faster.
>
> BUT sorting a list requires moving the data around quite a lot, AND
> sorting something that actually reverses it can be a pathologically bad
> case (e.g. if the engine uses any variant of quicksort())..
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
1234 ... 7