std.regex performance
Andrej Mitrovic
andrej.mitrovich at gmail.com
Wed Feb 8 14:41:28 PST 2012
On 2/8/12, David Nadlinger <see at klickverbot.at> wrote:
> On 2/8/12 10:44 PM, Jesse Phillips wrote:
>> foreach(w; std.string.split(readText(name)))
>> if(!match(w, regex(r"\d")).empty)
>> {}
>> }
>
> Could it be that you are rebuilding the regex engine on every iteration
> here?
Yup. This one is a steady 80 msecs (ctRegex seems to be a bit slower
in this case for some reason):
import std.file;
import std.datetime;
import std.regex;
import std.stdio;
private int[string] model;
void main()
{
auto sw = StopWatch(AutoStart.yes);
auto rg = regex(r"\d");
foreach (w; std.string.split(readText("uk.dic")))
if (!match(w, rg).empty) { }
writeln(sw.peek.msecs);
}
More information about the Digitalmars-d
mailing list