Based on what Bob said, here is my version of that handler: on mouseUp local tA, tB, tC, tD, tAll, tStart, tEnd put fld "A" into tA put fld "B" into tB put fld "C" into tC put fld "D" into tD -- put the milliseconds into tStart split tA by cr split tB by cr split tC by cr split tD by cr repeat with i=1 to the number of lines of the keys of tA put i & tab & tA[i] & tab & tB[i] & tab & tC[i] & tab & tD[i] & cr after tAll end repeat delete the last char of tAll put the milliseconds into tEnd put (tEnd - tStart) & cr & tAll into fld "result" end mouseUp
I used very short lines, but this way was 3/4ms; my initial method was 6/7ms; your original method was 15/16ms. On Fri, Aug 19, 2022 at 6:09 PM Bob Sneidar via use-livecode < use-livecode@lists.runrev.com> wrote: > Off the top of my head: > > split v1 by tab > split v2 by tab > split v3 by tab > split v4 by tab > > put the keys of v1 into tKeyList > sort tKeyList ascending numeric > > repeat for each line tKey in tKeyList > put tKey & tab & v1 [tKey] & tab & v2 [tKey] & tab & v3 [tKey] & tab & > v4 [tKey] & cr after tCombined > end repeat > > Not sure if this will be faster, but every time you refer to a line of a > string the engine has to parse out where that line is from the beginning. > Parsing times will increase exponentially (is that the right term?) the > more lines you are parsing in both the source strings AND the destination > string. > > But arrays are indexed memory locations so the engine knows exactly where > every bit of text is. And putting something after a string does not have to > parse to find the end, the engine knows where that is in memory. It might > be even faster though if you build an array as output and then use the > combine command to convert it all at once to a string. > > I am assuming of course that splitting does not put lines of text in > random order in the array. Arrays can be dicey that way. > > Bob S > > > > > On Aug 19, 2022, at 14:09 , Paul Dupuis via use-livecode < > use-livecode@lists.runrev.com> wrote: > > > > I have a set of fields, call them A, B, C, and D. Each has the same > number of lines. Each field has different text (per line) > > > > I need to combine the data - frequently - into a form that look like: > > > > <i><tab><line i of fld A><tab><line i of fld B><tab><line i of fld > C><tab><line i of fld D><cr> > > > > For the number of lines in the set of fields. Currently I do this as > follows: > > > > put empty into vCombined > > put fld A into v1 > > put fld B into v2 > > put fld C into v3 > > put fld D into v4 > > repeat with i=1 to the number of lines in v1 > > put i &tab& line i of v1 &tab& line i of v2 &tab& line i of v3 &tab& > line i of v4 into line i of vCombined > > end repeat > > > > I put the field contents into variable before the loop to combine them > as my understanding is variable access is faster than field access in a loop > > > > My question to the Hivemind is: Is there a noticeably faster way to > covert these field to the tab delimited structure as show above than the > code above? > > > > This current takes about 20 seconds for 2000 lines or about a second per > 100 lines (very roughly, I was not using a timer in my code, just my > wristwatch seconds in the IDE debugger between breakpoints) > > > > Thank you for any pointers in advance, > > > > Paul Dupuis > > Researchware > > > > > > _______________________________________________ > > use-livecode mailing list > > use-livecode@lists.runrev.com > > Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > > http://lists.runrev.com/mailman/listinfo/use-livecode > > > _______________________________________________ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode > _______________________________________________ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode