... to convert a Rexx variable containing a string of space-delimited words into a Rexx array whose elements are those words?
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
One way to start is: string = space(string,1,',') to get one comma between each word. Then put string between [ and ]. Maybe.
Sorta wingin' here. BobH On Mon, Oct 31, 2011 at 11:43 AM, George Hovey <[hidden email]> wrote: ... to convert a Rexx variable containing a string of space-delimited words into a Rexx array whose elements are those words? _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
On 31 October 2011 11:11, Robert Hamilton <[hidden email]> wrote: One way to start is: string = space(string,1,',') to get one comma between each word. Then put string between [ and ]. Maybe. For fun I ran some comparisons looping on Rexx.words() and String.split() and got the following: word count: 4320
Min, max and avg time for 100 iterations to create a Rexx array using String.split: 0.000903 0.067337 0.003178
word count: 4320 Min, max and avg time for 100 iterations to create a Rexx array using Rexx.words:
0.265916 0.461035 0.284033 word count: 4320
Min, max and avg time for 100 iterations to create a String array using String.split: 0.000700 0.002405 0.000794
So it would appear that using the String.split() method is faster than Rexx.words() by an order of magnitude. If you can get awat with a String[] then String.split() is even more efficient. Here's my test program: /* NetRexx */ options replace format comments java nocrossref savelog symbols
lipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit." -
"Duis et sem elit, id ullamcorper erat." - "Maecenas dictum suscipit neque, non pharetra velit aliquet sit amet." -
"Cras tincidunt, orci at tempus tincidunt, ligula tellus rutrum est," - "hendrerit congue lectus justo vel tortor." -
"Vivamus sit amet consequat tellus." - "Pellentesque sapien augue, ornare ac tempor id, eleifend id nisl." -
"Aliquam ultricies mauris ac velit mollis ut eleifend lorem hendrerit." - "Class aptent taciti sociosqu ad litora torquent per conubia nostra," -
"per inceptos himenaeos." - "Nulla facilisi." -
"Morbi ultricies faucibus vulputate." - "Nam lobortis, nibh id accumsan porttitor, urna dolor lacinia lectus," -
"vitae placerat risus sapien id lorem." - "Etiam semper magna a lorem vestibulum eu scelerisque mi convallis." -
"Ut condimentum tristique sem, eget adipiscing nunc venenatis sit amet." - "Phasellus laoreet laoreet facilisis." -
"Nullam nulla leo, imperdiet ut tristique vitae, tempor sed arcu." loop for 5 lipsum = lipsum lipsum end
startTime = long endTime = long
Numeric digits 20 tests = 100 tmin = Long.MAX_VALUE
tmax = Long.MIN_VALUE tsum = 0 loop for tests
startTime = System.nanoTime() lipsumRWords = RexxArrayViaStringSplit(lipsum)
endTime = System.nanoTime() tmin = Math.min(endTime - startTime, tmin)
tmax = Math.max(endTime - startTime, tmax) tsum = tsum + endTime - startTime
end tavg = tsum / tests say 'word count:' lipsumRWords.length
say 'Min, max and avg time for' tests 'iterations to create a Rexx array using String.split:' say (tmin / 1000000000).format(null, 6) (tmax / 1000000000).format(null, 6) (tavg / 1000000000).format(null, 6)
say lipsumRWords = null tmin = Long.MAX_VALUE tmax = Long.MIN_VALUE
tsum = 0
loop for tests startTime = System.nanoTime() lipsumRWords = RexxArrayViaRexxWords(lipsum)
endTime = System.nanoTime() tmin = Math.min(endTime - startTime, tmin)
tmax = Math.max(endTime - startTime, tmax) tsum = tsum + endTime - startTime
end tavg = tsum / tests say 'word count:' lipsumRWords.length
say 'Min, max and avg time for' tests 'iterations to create a Rexx array using Rexx.words:' say (tmin / 1000000000).format(null, 6) (tmax / 1000000000).format(null, 6) (tavg / 1000000000).format(null, 6)
say lipsumRWords = null tmin = Long.MAX_VALUE tmax = Long.MIN_VALUE
tsum = 0
loop for tests startTime = System.nanoTime() lipsumSWords = StringArrayViaStringSplit(lipsum)
endTime = System.nanoTime() tmin = Math.min(endTime - startTime, tmin)
tmax = Math.max(endTime - startTime, tmax) tsum = tsum + endTime - startTime
end tavg = tsum / tests say 'word count:' lipsumSWords.length
say 'Min, max and avg time for' tests 'iterations to create a String array using String.split:' say (tmin / 1000000000).format(null, 6) (tmax / 1000000000).format(null, 6) (tavg / 1000000000).format(null, 6)
say lipsumSWords = null return method RexxArrayViaStringSplit(wordList) private static binary returns Rexx[]
sWords = wordList.toString.split("\\s+") rWords = Rexx[sWords.length]
loop r_ = 0 to sWords.length - 1 rWords[r_] = sWords[r_]
end r_ return rWords
method RexxArrayViaRexxWords(wordList) private static binary returns Rexx[]
rWords = Rexx[wordList.words] loop r_ = 1 to wordList.words
rWords[r_ - 1] = wordList.word(r_) end r_ return rWords method StringArrayViaStringSplit(wordList) private static binary returns String[]
sWords = wordList.toString.split("\\s+")
return sWords Alan. Can't tweet, won't tweet! _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
Alan
-- Needs more cowbell. |
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
Dave,
I wondered if I was missing any Rexx method that did this in an efficient way -- those I thought could be used to concoct a solution all seemed to require multiple passes over the characters. As you and Mike point out, String.Split beats the Rexx approaches, even using regular expressions, and I can use this. Thanks for your help! On Tue, Nov 1, 2011 at 2:40 AM, Mike Cowlishaw <[hidden email]> wrote:
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
On 1 November 2011 05:28, George Hovey <[hidden email]> wrote: Dave, Dave? I wondered if I was missing any Rexx method that did this in an efficient way -- those I thought could be used to concoct a solution all seemed to require multiple passes over the characters. As you and Mike point out, String.Split beats the Rexx approaches, even using regular expressions, and I can use this. Alan.
Can't tweet, won't tweet! _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
Alan
-- Needs more cowbell. |
In reply to this post by alansam
Hello Alan, thanks for your testcase (and the resulting FINDINGS)...
... and it's also GOOD to recall my ancient LATIN Knowledge again;-) Thomas. =================================================================================== Am 31.10.2011 21:33, schrieb Alan Sampson:
--
Thomas Schneider (Founder of www.thsitc.com) Member of the Rexx Languge Asscociation (www.rexxla.org) Member of the NetRexx Developer's Team (www.netrexx.org) _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
Thomas Schneider, Vienna, Austria (Europe) :-)
www.thsitc.com www.db-123.com |
In reply to this post by alansam
On 11/1/11 16:11 Alan Sampson said:
> > Leveraging/plundering the Java class library to solve problems is one > of NetRexx's major strengths and a significant reason why the language > itself doesn't need to be significantly altered. THANK YOU, Alan! Please say that often, loud & proud. René, I think we have a new quote for the netrexx.org website. -Chip- _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
Free forum by Nabble | Edit this page |