[REBOL] Re: Fast way to remove all non-numerical chars from a string
From: carl:cybercraft at: 23-Sep-2007 10:19
On Saturday, 22-September-2007 at 14:17:45 Petr Krenzelok wrote,
>Hi,
>
>well, as with REBOL, another, totally different aproach, the short one :-)
>
>start: now/time/precise
>loop 1'000'000 [remove-each val "1234a5b6v77" [any [val < #"0" val > #"9"]]]
>now/time/precise - start
>
>== 0:00:06.255
>
>But - parse is usually the fastest method, otoh remove-each is native,
>it could compare rather well. Parse is more flexible for more
>complicated set-ups though ...
Being native's the reason I thought of using trim too - and with good reason, it seems...
The script...
-----------------
rebol []
print "remove-each..."
start: now/time/precise
loop 1'000'000 [remove-each val "1234a5b6v77" [any [val < #"0" val > #"9"]]]
print now/time/precise - start
print "trim/with..."
chrs: ""
repeat n 256 [append chrs to-char n - 1]
chrs: exclude chrs "1234567890"
start: now/time/precise
loop 1'000'000 [trim/with "1234a5b6v77" chrs]
print now/time/precise - start
-----------------
And the results...
>> do %/c/program files/rebol/view/test.r
Script: "Untitled" (none)
remove-each...
0:00:07.313
trim/with...
0:00:02.343
Now if onlt trim worked as expected! (Someone else can add the parse test... And Kai,
like to give us some real-world results?)
-- Carl Read.