REBOL.net

Re: Fast way to remove all non-numerical chars from a string

Tom (Tom.Conlin)
22-Sep-2007/22:50:08-4:00
#43056
<Back   Thread   Next>
<Back   Index   Next>

I got 03.265 for parse and 03.391 for trim all
in this range it could be due to the vagueries
of the operating system tasks

with Peter Wood's 'some improvement I see

=3D=3D 0:00:02.047

trim/with is still coming in at  0:00:03.391 on multiple runs


Carl Read wrote:
> On Saturday, 22-September-2007 at 17:22:49 Tom wrote,
>=20
>> minutely faster than trim/with
>>
>> digit: charset "0123456789"
>> noise: complement digit
>> start: now/time/precise
>> rule: [digit | here: some noise there:(remove/part :here :there) :here=
]
>> loop 1'000'000 [parse/all "(250) 764-0929"[some rule]]
>> now/time/precise - start
>=20
> Ahah!  I'm finding it minutely slower...
>=20
> remove-each...
> 0:00:08.734
> trim/with...
> 0:00:02.203
> remove-each using bitsets...
> 0:00:07.032
> parse...
> 0:00:02.265
>=20
> but still an excellent advert for parse.  And unlike trim, it doesn't e=
asily break...
>=20
>>> str: ""
> =3D=3D ""
>>> loop 50 [append str to-char random 255]
> =3D=3D {^!=D9=D7V^[=D9l=ACw=D7G=CFp=D7f~=87<8~=82^S|U#^Q=BA|o$]O=9B=A4y=
=8C=9E/#|Y^\j=B8e=8B=FC=89=82!}
>>> loop 1'000'000 [parse/all str [some rule]]
> =3D=3D true
>>> str
> =3D=3D "8"
>=20
> So Kai - up to you for the real-world results, though parse looks to be=
 the best choice.
>=20
> -- Carl Read.
>=20



<Back   Thread   Next>
<Back   Index   Next>

REBOL.com