Formatting parameter for combine and split

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Formatting parameter for combine and split

Post by [-hh] » Sat Aug 17, 2013 10:00 am

..........
Last edited by [-hh] on Wed Aug 13, 2014 12:21 pm, edited 1 time in total.
shiftLock happens

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3400
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Formatting parameter for combine and split

Post by bn » Sat Aug 17, 2013 8:01 pm

Hi HH,
combine <A> will respect a param or global 'valueBeforeKey' that makes (value,key) the output order for each element of <A> with a onedimensional array <A>
Livecode is really quite fast at rearranging lists if you do it right. Livecode is fastest if you append to a variable but gets really slow if you prepend (put before) a variable.
And if you use "repeat for each" you get a really fast handler.

I did a test with a list of 100,000 lines (oneHundredThousand)
a line consisted of 20 random words of five chars each then a tab and a number. see example below.
---------------------
fxezr fxezr fxezr fxezr ugbiq ugbiq fxezr fxezr fxezr ugbiq ugbiq fxezr ugbiq fxezr fxezr ugbiq ugbiq ugbiq fxezr fxezr 4
-------------------------
pretty much what you would get from a combine when looking for duplicate lines.

I used this code

Code: Select all

on mouseUp
   put field "result" into tData
   put the milliseconds into tStart
   set the itemDelimiter to tab
   repeat for each line aLine in tData
      put item 2 of aLine & tab & item 1 of aLine & cr after tCollect
   end repeat
   delete last char of tCollect
   put the milliseconds - tStart into field "computationTime"
   put tCollect into field "result"
end mouseUp
It took 390 milliseconds to rearrange the list -> number first then a tab and then the 20 words (MacBook Pro core i5 2.53 GHz)

That is not too shabby and I don't know if this necessitates additional syntax for combine.

Kind regards
Bernd

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Formatting parameter for combine and split

Post by [-hh] » Sat Aug 17, 2013 10:24 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 12:21 pm, edited 1 time in total.
shiftLock happens

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3400
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Formatting parameter for combine and split

Post by bn » Sun Aug 18, 2013 9:39 pm

Hi HH

I agree with you that combine is faster, and your feature request will give even faster results in special situations

My point is that in special situations like you describe the performance hit is small using repeat.

If you generate the list that combine gives you by reading out the array with

Code: Select all

repeat for each key aKey in tArray
you can at the same time do your formatting for the resulting list.

in the case of an array with 100,000 keys/values combine takes about 280 milliseconds. Above technique 380 to 410 milliseconds
So the overhead of doing "repeat" is about 130 milliseconds.

or in the case of your stack "counted sets part 1" with 624 distinct lines combine takes about 680 - 700 MIKROseconds and above technique about 950 - 1000 MIKROseconds. (measuring in Microseconds = the long seconds, is not very precise)

The same probably applies to split.

Kind regards
Bernd

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Formatting parameter for combine and split

Post by [-hh] » Tue Aug 20, 2013 2:51 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 12:21 pm, edited 1 time in total.
shiftLock happens

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3400
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Formatting parameter for combine and split

Post by bn » Tue Aug 20, 2013 9:10 pm

Hi HH,

glad you liked it. And you put it to perfect use in your new versions of Counted Set stacks.

That was the whole point: "repeat for each" allows for speed almost as if the engine provides a certain output format for arrays but "repeat for each" is much more flexible.

Kind regards
Bernd

Post Reply

Return to “Feature Proposals”