Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Fast way to strip characters

From: compkarori:gma:il at: 7-Oct-2009 1:07

Peter Trim modifies the string in situ. Your trim code only does it once but parse is working 10,000 x. On Wed, Oct 7, 2009 at 6:51 PM, Peter Wood <pwawood-gmail.com> wrote:
> 2009/10/7 Izkata <izkata-gmail.com> > >> >> If all you're doing is stripping characters, I suggest 'trim - >> >> >> trim/with {I'm so not here} {' } >> == "Imsonothere" >> >> Is parse faster in this case? >> >> > Trim is much faster than parse for your example. It is a native function. > speedtest: func [][ > =A0 =A0st: now/precise > =A0 =A0loop 10000 [stripped: trim/with teststring "' "] > =A0 =A0et: now/precise > =A0 =A0print ["10000 trim/with took:" difference et st] > =A0 =A0st: now/precise > =A0 =A0strip: charset [#" " #"'"] > =A0 =A0not-strip: complement strip > =A0 =A0loop 10000 [ > =A0 =A0 =A0 =A0stripped: copy "" > =A0 =A0 =A0 =A0parse teststring [any [copy str some not-strip (insert tail stripped > str) | some strip]] > =A0 =A0] > =A0 =A0et: now/precise > =A0 =A0print ["10000 parse took:" difference et st] > ] > >>> speedtest > 10000 trim/with took: 0:00:00.007205 > 10000 parse took: 0:00:00.05729 > > Regards > Peter > > -- > To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject. >
-- Graham Chiu http://www.synapsedirect.com Synapse - the use from anywhere EMR.