strip chars
-= JB =-
sundown at pacifier.com
Fri Jul 25 13:23:42 EDT 2008
That is interesting and nice.
I have only run one test but it was mixed pretty good &
my result was 94 67 with the repeat for each being the
fastest method.
Thanks to both Mark & Richard for the valuable help.
-=>JB<=-
On Jul 25, 2008, at 7:06 AM, Richard Gaskin wrote:
> RegEx solutions are conveniently compact to write, but given the
> complexity of the RegEx subsystem they tend to be slower than more
> brute-force solutions.
>
> Being a benchmarking fan I couldn't resist testing this latest
> case, extracting numerals from an alphanumeric string.
>
> Below is a test handler which calls two functions, the first using
> RegEx and the second using "repeat for each". To run just put a
> button and three fields on a card, and put some alphanumeric test
> into the first field. It takes the text from field 1 and runs it
> through each of the two functions, putting the results into flds 2
> and 3 and then displaying in the Message Box the execution times
> and whether the results matched (useful to make sure the algos are
> doing the same job).
>
> In my tests here on strings long and short the "repeat for each"
> method seems roughly twice as fast as the RegEx one.
>
>
> on mouseup
> put fld 1 into tSrc
> put 1000 into n
> --
> -- ReplaceText:
> --
> put the millisecs into t
> repeat n
> get rplText(tSrc)
> end repeat
> put the millisecs - t into t1
> put it into fld 2
> --
> -- Repeat for Each:
> --
> put the millisecs into t
> repeat n
> get rptText(tSrc)
> end repeat
> put the millisecs - t into t2
> put it into fld 3
> --
> -- Results:
> put t1 && t2 &cr& (fld 2 = fld 3)
> end mouseup
>
>
> function rplText pSrc
> return replacetext( pSrc ,"[^0-9]","")
> end rplText
>
>
> function rptText pSrc
> put empty into s
> repeat for each char k in pSrc
> if k is in "0123456789" then put k after s
> end repeat
> return s
> end rptText
>
>
> --
> Richard Gaskin
> Managing Editor, revJournal
> _______________________________________________________
> Rev tips, tutorials and more: http://www.revJournal.com
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
More information about the use-livecode
mailing list