Solved

Regex IsMatch -- Profiling Performance Comparison

Posted on 2006-11-29
4
282 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 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