?
Solved

Regex IsMatch -- Profiling Performance Comparison

Posted on 2006-11-29
4
Medium Priority
?
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

800 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