-
Notifications
You must be signed in to change notification settings - Fork 105
Open
Description
Hi all,
I ran the following test to check how well verbal expression performs compared to a regular expression:
[Test]
public void TestingIfWeHaveAValidURL()
{
var testMe = "https://www.google.com";
var swVerb = new Stopwatch();
swVerb.Start();
verbEx = VerbalExpressions.DefaultExpression
.StartOfLine()
.Then("http")
.Maybe("s")
.Then("://")
.Maybe("www.")
.AnythingBut(" ")
.EndOfLine();
Assert.IsTrue(verbEx.Test(testMe), "The URL is incorrect");
swVerb.Stop();
var swRegex = new Stopwatch();
swRegex.Start();
var regex = new Regex( @"^http(s)?://([\w-]+.)+[\w-]+(/[\w- ./?%&=])?$" );
Assert.IsTrue( regex.IsMatch( testMe ) );
swRegex.Stop();
//Verb: 133 ms Regex: 4 ms
Console.WriteLine("Verb: {0} Regex: {1}", swVerb.ElapsedMilliseconds, swRegex.ElapsedMilliseconds);
}
I ran it a couple of times and verbal expression runs at about 130 milliseconds, while regular expression runs in about 5 ms.
Same results returned in other tests I did.
I'm considering using the verbal expression in my indexing project, so this time gap is too big.
What do you think?
Thanks
Metadata
Metadata
Assignees
Labels
No labels