Solved

Regex IsMatch -- Profiling Performance Comparison

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

696 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