Solved

Regex IsMatch -- Profiling Performance Comparison

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

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