What I found, where LC is close to unbeatable, is the creation of strings, that are a repeat of a "pattern" (any "basestring").
For small numbers of pattern-repeats nearly every repeat method is OK. But for large N (say N > 1024) or on a slow machine (Raspi) or a long basestring or a lot of repeated calls of the function (say more than 1000 repeats, may add up to these on one day) there are drastic differences. We all know and have experienced that.
Also, a repeat with i=1 to N, or a N-times repeat for each, or something that is starting such a repeat internally (like to put comma into item N of an empty string), is certainly not able to keep up with the IDE's mentioned above.
But this works to put LC on the top, The "Doubling Method":
The input basestring is doubled with each repeat until it's length is greater than or equal to the length goal.
Included are two examples, you need a button, a fld "timing" and one new image (=img 1), not too small, say 600x400 px.
[Edit. Don't use the following "function version". LC does internally textconversion with this and LC 7 is very slow with this. Instead you could use (the same code) as "inline version", see post below. Sorry, I tested the "inline version" and thought it would increase readability to post this "function version"].
Code: Select all
-- THE DOUBLING METHOD --
private function repeatString str, N
put str into s
put length(str)*N into n0
put trunc(log2(n0)) into M
# --> if you KNOW that n0 is a power of 2 then omit the next check
if 2^M < n0 then add 1 to M
repeat M
put s after s
end repeat
return char 1 to n0 of s
end repeatString
on mouseUp -- Example 1: "Image", filling with color, here a "pattern"
put the millisecs into strt
set cursor to watch
put numToByte(0) into c0; put numToByte(255) into c1
put c0 & c0 & c0 & c0 & c0 & c0 & c0 & c0 & \
c0 & c1 & c0 & c0 & c0 & c1 & c0 & c0 & \
c0 & c0 & c0 & c0 & c0 & c0 & c0 & c0 into s0
put the width of img 1 into w; put the height of img 1 into h
-- we need 4*w*h bytes, here w*h/6, because length(s0)=24
set imageData of image 1 to repeatString(s0, w*h div 6 )
put the millisecs - strt && "millsecs for" && \
(w*h) && "pixels of 32 bit each" into fld "timing"
select text of fld "timing"
end mouseUp
on mouseUp -- Example 2 "Text": 2^10 x 2^11 lines of len 23 = 46 MByte
put the millisecs into strt
set cursor to watch
put 2^10 into r --> repeats 2^10 times the test
repeat r
put "0, 1, 2, 3, 4, 5, 6, 7"& cr into s0
put repeatString(s0,2^11) into nirwana --> 2^11 lines of s0
end repeat
put the millisecs - strt && "millsecs for" && \
r*length(nirwana) / 2^20 && "MByte of TEXT" into fld "timing"
select text of fld "timing"
end mouseUp
Ex 1 needs in average 55 [45] millisecs (600x400 image=240000 px = 960 KByte),
Ex 2 needs in average 520 [1560] millisecs (result has 46 MByte).
You may have a faster method for special cases, for example when repeating one single char. It would be fine if such methods could be posted here, together with the comparison results to the 'doubling method' above on your machine (use the above examples, please).