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

[REBOL] Re: Fast way to strip characters

From: pwawood:gma:il at: 7-Oct-2009 16:00

> Peter > > Trim modifies the string in situ. > > Your trim code only does it once but parse is working 10,000 x.
Oops, I forgot about Rebol's side effects for a moment. However the trim code did it 10,000 times but didn't have so much to do 9999 of them. This is a better test and still indicates trim is faster for this example: speedtest: func [][ st: now/precise loop 10000 [ teststring: copy "I'm so not here" stripped: trim/with teststring "' " ] et: now/precise print ["10000 trim/with took:" difference et st] st: now/precise strip: charset [#" " #"'"] not-strip: complement strip loop 10000 [ teststring: copy "I'm so not here" stripped: copy "" parse teststring [any [copy str some not-strip (insert tail stripped str)| some strip]] ] et: now/precise print ["10000 parse took:" difference et st] ]
>> speedtest
10000 trim/with took: 0:00:00.013725 10000 parse took: 0:00:00.073276 Regards Peter