[REBOL] Re: Fast way to strip characters
From: pwawood:gm:ail at: 7-Oct-2009 13:51
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 [][
st: now/precise
loop 10000 [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 [
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.007205
10000 parse took: 0:00:00.05729
Regards
Peter