Why do the same work about 'IndexOfAny' and 'indexOf' function?

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 9 06:03:11 PST 2015


On Fri, 09 Jan 2015 13:54:00 +0000
Robert burner Schadek via Digitalmars-d-learn
<digitalmars-d-learn at puremagic.com> wrote:

> On Friday, 9 January 2015 at 13:25:17 UTC, ketmar via 
> Digitalmars-d-learn wrote:
> > if you *really* concerned with speed here, you'd better 
> > consider using
> > regular expressions. as regular expression can be precompiled 
> > and then
> > search for multiple words with only one pass over the source 
> > string. i
> > believe that std.regex will use variation of Thomson algorithm 
> > for
> > regular expressions when it is able to do so.
> 
> IMO that is not sound advice. Creating the state machine and 
> running will be more costly than using canFind or indexOf how 
> basically only compare char by char.
> 
> If speed is really need use strstr and look if it uses sse to 
> compare multiple chars at a time. Anyway benchmark and then 
> benchmark some more.
std.regex can use CTFE to compile regular expressions (yet it sometimes
slower than non-CTFE variant), and i mean that we compile regexp before
doing alot of searches, not before each single search. if you have alot
of words to match or alot of strings to check, regexp can give a huge
boost.

sure, it all depends of code patterns.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150109/caf802a7/attachment.sig>


More information about the Digitalmars-d-learn mailing list