Solved

Regex IsMatch -- Profiling Performance Comparison

Posted on 2006-11-29
4
280 Views
Last Modified: 2007-12-19
I don't have profiling tools handy with me (like Compuware DevPartner stuff). Can someone add a button (Button1) to a form and add this code:

'''''
Imports System.Text.RegularExpressions
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myName As String = "Randy Given"
        If myName.Substring lSubstring(2, 1) = "n" Then
            Debug.WriteLine("myName.Substring(2, 1) = n")
        End If
        If Regex.IsMatch(myName.Substring(2, 1), "n") Then
            Debug.WriteLine("Regex.IsMatch(myName.Substring(2, 1), n)")
        End If
        If myName.Substring(2, 1) = "d" Then
            Debug.WriteLine("myName.Substring(2, 1) = d")
        End If
        If Regex.IsMatch(myName.Substring(2, 1), "d") Then
            Debug.WriteLine("Regex.IsMatch(myName.Substring(2, 1), d)")
        End If
    End Sub
End Class
'''''

Can you tell me what the profiling shows? Trying to see the difference between straight compare and a regex version.
0
Comment
Question by:GivenRandy
  • 2
  • 2
4 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 18044854
Randy are you looking to do this within a For loop that executes 1000's of times?  Otherwise it is pretty pointless to think about speed differences with such basic code.

Bob
0
 
LVL 9

Author Comment

by:GivenRandy
ID: 18044935
I'm mostly curious. I always keep performance in the back of my mind, but usually only spend development time when it is critical (like you pointed out). I used to have the tools to do this, but don't anymore.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18045064
If you are looking to check this code, I can tell you without even checking that regular expressions vs. simple substrings are inherently less optimized.  Regular expression engines are powerful, but can be slow, since the checking is done iteratively, and sequentially.

Bob
0
 
LVL 9

Author Comment

by:GivenRandy
ID: 18045396
That's my assumption, too. I'll back-burner this one, but your first post is spot-on and will accept that. Thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now